home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / reportplus / source / rp.c < prev    next >
C/C++ Source or Header  |  2002-10-27  |  101KB  |  2,823 lines

  1. /* $Filename:    ReportPlus/Source/rp.c
  2.  * $VER:         Report+ 5.63
  3.  * $Description: Multipurpose utility
  4.  *
  5.  * © Copyright 1999-2002 James R. Jacobs. Freely distributable.
  6.  *        _
  7.  *       //      -=AMIGA=-
  8.  *      //
  9.  * _   //
  10.  * \\ //
  11.  *  \X/
  12.  
  13. #INCLUDES -------------------------------------------------------------- */
  14.  
  15. /* #include <assert.h> */
  16.  
  17. #include <exec/types.h>
  18. #include <exec/alerts.h>
  19. #include <exec/nodes.h>
  20. #include <exec/memory.h>
  21. #include <exec/execbase.h>
  22. #include <proto/exec.h>
  23. #include <intuition/intuition.h>
  24. #include <clib/intuition_protos.h>
  25. #include <intuition/gadgetclass.h>
  26. #include <libraries/gadtools.h>
  27. #include <clib/gadtools_protos.h>
  28. #include <libraries/iffparse.h>
  29. #include <workbench/workbench.h> /* struct DiskObject */
  30. #include <libraries/asl.h>
  31. #include <proto/asl.h>
  32. #include <dos/dos.h>
  33. #include <dos/dostags.h>
  34. #include <dos/dosextens.h>
  35. #include <proto/dos.h>
  36. #include <graphics/gfx.h>
  37. #include <graphics/displayinfo.h>
  38. #include <graphics/gels.h>
  39. #include <clib/graphics_protos.h>
  40. #include <utility/tagitem.h>
  41. #include <proto/utility.h>
  42. #include <workbench/icon.h>
  43. #include <clib/icon_protos.h>
  44. #include <clib/alib_protos.h>
  45. #include <resources/battmem.h>
  46. #include <resources/battmembitsamiga.h>
  47. #include <resources/battmembitsshared.h>
  48.  
  49. #define ALL_REACTION_CLASSES
  50. #define ALL_REACTION_MACROS
  51. #include <reaction/reaction.h>
  52. #include <clib/alib_protos.h>
  53. #include <clib/texteditor_protos.h>
  54. #include <gadgets/texteditor.h>
  55. #include <pragmas/texteditor_pragmas.h>
  56.  
  57. #define GID_0_LY1   0
  58. #define GID_0_BU1   1 // the function buttons must start from GID_0_BU1,
  59. #define GID_0_BU2   2 // and must all be consecutive.
  60. #define GID_0_BU3   3
  61. #define GID_0_BU4   4
  62. #define GID_0_BU5   5
  63. #define GID_0_BU6   6
  64. #define GID_0_BU7   7
  65. #define GID_0_BU8   8
  66. #define GID_0_BU9   9
  67. #define GID_0_BU10 10
  68. #define GID_0_ST1  11
  69. #define GIDS_0     GID_0_ST1
  70.  
  71. #define GID_A_LY1  0
  72. #define GIDS_A     GID_A_LY1
  73.  
  74. #include <ctype.h>
  75. #include <stdio.h>          /* FILE, printf() */
  76. #include <stdlib.h>         /* EXIT_SUCCESS, EXIT_FAILURE */
  77. #include <string.h>
  78. #include "rp.h"
  79. #include "boards.h"
  80.  
  81. #ifdef __STORM__
  82.    #pragma chip
  83. #endif
  84.  
  85. MODULE struct Image*  image[FUNCTIONS + 1];
  86. MODULE struct BitMap* bitmap[FUNCTIONS + 1];
  87. MODULE STRPTR         imagename[FUNCTIONS + 1] =
  88. {   "PROGDIR:images/f1.ilbm",
  89.     "PROGDIR:images/f2.ilbm",
  90.     "PROGDIR:images/f3.ilbm",
  91.     "PROGDIR:images/f4.ilbm",
  92.     "PROGDIR:images/f5.ilbm",
  93.     "PROGDIR:images/f6.ilbm",
  94.     "PROGDIR:images/f7.ilbm",
  95.     "PROGDIR:images/f8.ilbm",
  96.     "PROGDIR:images/f9.ilbm",
  97.     "PROGDIR:images/f10.ilbm",
  98.     "PROGDIR:images/amigan.ilbm"
  99. };
  100. MODULE STRPTR FunctionDesc[FUNCTIONS + 2] =
  101. {   // Edit
  102.     "Bug report",         // 1
  103.     "Aminet readme",      // 2
  104.     "Battery-backed RAM", // 9
  105.     // View
  106.     "Manufacturer IDs",   // 5
  107.     "IFF FORMs",          // 6
  108.     // Process
  109.     "Icons",              // 4
  110.     "EOLs/tabs",          // 7
  111.     // Report
  112.     "Path size",          // 8
  113.     "System files",       // 10
  114.     // Conduct
  115.     "ACSE test",          // 3
  116.     // (default)
  117.     TITLEBARTEXT
  118. };
  119.  
  120. #define MENUENTRIES 11
  121. MODULE struct NewMenu NewMenu[MENUENTRIES] =
  122. {   { NM_TITLE, "Project",       0 , 0,               0, 0},
  123.     {  NM_ITEM, "New",          "N", NM_ITEMDISABLED, 0, 0},
  124.     {  NM_ITEM, "Open...",      "O", NM_ITEMDISABLED, 0, 0},
  125.     {  NM_ITEM, NM_BARLABEL,     0 , 0,               0, 0},
  126.     {  NM_ITEM, "Save",         "S", NM_ITEMDISABLED, 0, 0},
  127.     {  NM_ITEM, "Save As...",   "A", NM_ITEMDISABLED, 0, 0},
  128.     {  NM_ITEM, NM_BARLABEL,     0 , 0,               0, 0},
  129.     {  NM_ITEM, "Quit Report+", "Q", 0,               0, 0},
  130.     { NM_TITLE, "Help",          0 , 0,               0, 0},
  131.     {  NM_ITEM, "About...",     "?", 0,               0, 0},
  132.     {   NM_END, NULL,            0 , 0,               0, 0}
  133. };
  134.  
  135. MODULE void clearkybd(void);
  136. MODULE void menu(void);
  137. MODULE void parsewb(void);
  138. MODULE void eachwildcard(STRPTR subpattern, ABOOL gui);
  139. MODULE void menu_loop(ULONG gid);
  140. MODULE void sender_loop(ULONG gid);
  141. MODULE void about_loop(void);
  142.  
  143. int CXBRK(void) { return(0); }    /* Disable SAS/C Ctrl-C handling */
  144. int chkabort(void) { return(0); } /* really */
  145.  
  146. MODULE  struct Window*           AboutWindowPtr  = NULL;
  147. AGLOBAL struct Library          *WindowBase      = NULL,
  148.                                 *LayoutBase      = NULL,
  149.                                 *ButtonBase      = NULL,
  150.                                 *TextEditorBase  = NULL,
  151.                                 *LabelBase       = NULL,
  152.                                 *ListBrowserBase = NULL,
  153.                                 *ChooserBase     = NULL,
  154.                                 *StringBase      = NULL,
  155.                                 *CheckBoxBase    = NULL,
  156.                                 *BoardsBase      = NULL,
  157.                                 *BitMapBase      = NULL,
  158.                                 *FuelGaugeBase   = NULL,
  159.                                 *IntegerBase     = NULL,
  160.                                 *RadioButtonBase = NULL,
  161.                                 *SpaceBase       = NULL;
  162. AGLOBAL TEXT                    asldir[PATHNAMEFIELD + 1],
  163.                                 aslresult[PATHNAMEFIELD + 1],
  164.                                 IOBuffer[LONGESTFIELD + 1],
  165.                                 string[LONGESTFIELD + 1],
  166.                                 weekdaystring[LEN_DATSTRING],
  167.                                 datestring[LEN_DATSTRING],
  168.                                 timestring[LEN_DATSTRING],
  169.                                 cpuline[VLONGFIELD + 1];
  170. AGLOBAL WORD                    xsize;
  171. AGLOBAL SBYTE                   page             = 0,
  172.                                 closer           = 0;
  173. AGLOBAL ULONG                   increment,
  174.                                 offset,
  175.                                 wbval,
  176.                                 aboutsignal,
  177.                                 signal;
  178. AGLOBAL ABOOL                   BattBuffer[96],
  179.                                 done             = FALSE,
  180.                                 ram              = FALSE,
  181.                                 stop             = FALSE;
  182. AGLOBAL struct Library*         IconBase         = NULL;
  183. AGLOBAL struct Menu*            MenuPtr          = NULL;
  184. AGLOBAL struct Screen*          ScreenPtr        = NULL;
  185. AGLOBAL struct Window*          MainWindowPtr    = NULL;
  186. AGLOBAL struct TextFont*        FontPtr          = NULL;
  187. AGLOBAL struct VisualInfo*      VisualInfoPtr    = NULL;
  188. AGLOBAL struct ExAllData*       EADataPtr        = NULL;
  189. AGLOBAL struct List             EmptyList,
  190.                                 FileList;
  191. AGLOBAL struct SharedStruct shared =
  192. {   0,
  193.     "", ""
  194. };
  195.  
  196. IMPORT struct ExecBase*     SysBase;
  197. // from f1.c
  198. IMPORT struct ReportStruct  report;
  199. // from f2.c
  200. IMPORT struct AminetStruct  aminet;
  201. // from f4.c
  202. IMPORT struct IconStruct    icon;
  203. IMPORT struct Gadget*       icon_gadgets[GIDS_4 + 1];
  204. IMPORT ABOOL                quit;
  205. // from f6.c
  206. IMPORT struct IFFStruct     iff;
  207. // from f7.c
  208. IMPORT struct Gadget*       eol_gadgets[GIDS_7 + 1];
  209. // from f8.c
  210. IMPORT struct SizeStruct    size;
  211. // from f9.c
  212. IMPORT struct Library*      BattMemBase;
  213. // from f10.c
  214. IMPORT struct FilesStruct   files;
  215.  
  216. AGLOBAL       Object*          WinObject[FUNCTIONS + 1]; // note that WindowObject is a reserved macro
  217. AGLOBAL struct TextAttr        Topaz8 =
  218. {    (STRPTR) "topaz.font", 8, FS_NORMAL, FPF_ROMFONT | FPF_DESIGNED
  219. }; // "topaz.font" is case-sensitive
  220.  
  221. MODULE BPTR                    NilHandle         = NULL;
  222. MODULE TEXT                    pubscreen[256 + 1];
  223. MODULE ABOOL                   logo              = TRUE;
  224. MODULE        Object*          AboutWinObject    = NULL;
  225. MODULE struct Gadget          *gadgets[GIDS_0 + 1],
  226.                               *sender_gadgets[GIDS_S + 1];
  227. MODULE struct RDArgs*          ArgsPtr           = NULL;
  228. MODULE struct WBArg*           WBArg             = NULL;
  229. MODULE struct WBStartup*       WBMsg             = NULL;
  230. MODULE struct ASLBase*         ASLBase           = NULL;
  231. MODULE struct GadToolsBase*    GadToolsBase      = NULL;
  232. MODULE struct IFFParseBase*    IFFParseBase      = NULL;
  233. MODULE struct IntuitionBase*   IntuitionBase     = NULL;
  234. MODULE struct Library*         VersionBase       = NULL;
  235. MODULE struct EasyStruct       EasyStruct =
  236. {   sizeof(struct EasyStruct),
  237.     0,
  238.     "Report+: Error",
  239.     NULL,
  240.     "Quit"
  241. };
  242.  
  243. /* FUNCTIONS -------------------------------------------------------------- */
  244.  
  245. int main(int argc, char** argv)
  246. {   UWORD  i;
  247.     SLONG  args[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  248.     SLONG  number = 0, hostid /* = 7 */ ;
  249.     BPTR   ConfigHandle /* = NULL */ ,
  250.            OldDir;
  251.  
  252.     /* Start of program.
  253.  
  254.     version embedding into executable */
  255.  
  256.     if (0) /* that is, never */
  257.         Printf("$VER: Report+ 5.63 (21.10.2002)"); /* always d.m.y format */
  258.  
  259.     for (i = 0; i <= FUNCTIONS; i++)
  260.     {   WinObject[i] = NULL;
  261.     }
  262.  
  263.     /* Check for OS3.9+... */
  264.     if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 40L)))
  265.     {   Printf("Report+: Need AmigaOS 3.9+!\n");
  266.         cleanexit(EXIT_FAILURE);
  267.     }
  268.     if (SysBase->LibNode.lib_Version < 40L)
  269.     {   Printf("Report+: Need AmigaOS 3.9+!\n");
  270.         cleanexit(EXIT_FAILURE);
  271.     }
  272.  
  273.     if (!(VersionBase = (struct Library *) OpenLibrary("version.library", 0L)))
  274.         rq("Can't open version.library!");
  275.     wbval = VersionBase->lib_Version;
  276.     CloseLibrary((struct Library *) VersionBase);
  277.     VersionBase = NULL;
  278.     if (wbval < 45)
  279.     {   Printf("Report+: Need AmigaOS 3.9+!\n");
  280.         cleanexit(EXIT_FAILURE);
  281.     }
  282.  
  283.     if (!(GadToolsBase = (struct ASLBase *) OpenLibrary("gadtools.library", 38L)))
  284.         rq("Can't open GadTools.library V38+!");
  285.     if (!(ASLBase = (struct ASLBase *) OpenLibrary("asl.library", 0L)))
  286.         rq("Can't open ASL.library!");
  287.     if (!(IFFParseBase = (struct IFFParseBase *) OpenLibrary("iffparse.library", 0L)))
  288.         rq("Can't open IFFParse.library!");
  289.     // it would be better to disable only the IFF viewer rather than abort
  290.     // the entire program.
  291.     if (!(FontPtr = OpenFont(&Topaz8)))
  292.     {   rq("Can't open Topaz 8 font!");
  293.     }
  294.  
  295.     if (!(ButtonBase      = OpenLibrary("gadgets/button.gadget", 44)))
  296.                        rq("OpenLibrary(\"gadgets/button.gadget\") failed!");
  297.     if (!(CheckBoxBase    = OpenLibrary("gadgets/checkbox.gadget", 44)))
  298.                        rq("OpenLibrary(\"gadgets/checkbox.gadget\") failed!");
  299.     if (!(ChooserBase     = OpenLibrary("gadgets/chooser.gadget", 44)))
  300.                        rq("OpenLibrary(\"gadgets/chooser.gadget\") failed!");
  301.     if (!(LabelBase       = OpenLibrary("images/label.image", 44)))
  302.                        rq("OpenLibrary(\"images/label.image\") failed!");
  303.     if (!(LayoutBase      = OpenLibrary("gadgets/layout.gadget", 44)))
  304.                        rq("OpenLibrary(\"gadgets/layout.gadget\") failed!");
  305.     if (!(ListBrowserBase = OpenLibrary("gadgets/listbrowser.gadget", 0)))
  306.                        rq("OpenLibrary(\"gadgets/listbrowser.gadget\") failed!");
  307.     if (!(StringBase      = OpenLibrary("gadgets/string.gadget", 44)))
  308.                        rq("OpenLibrary(\"gadgets/string.gadget\") failed!");
  309.     if (!(TextEditorBase  = OpenLibrary("gadgets/texteditor.gadget", 0)))
  310.                        rq("OpenLibrary(\"gadgets/texteditor.gadget\") failed!");
  311.     if (!(WindowBase      = OpenLibrary("window.class", 44)))
  312.                        rq("OpenLibrary(\"window.class\") failed!");
  313.     if (!(BitMapBase      = OpenLibrary("images/bitmap.image", 44)))
  314.                        rq("OpenLibrary(\"images/bitmap.image\") failed!");
  315.     if (!(FuelGaugeBase   = OpenLibrary("gadgets/fuelgauge.gadget", 0)))
  316.                        rq("OpenLibrary(\"gadgets/fuelgauge.gadget\") failed!");
  317.     if (!(IntegerBase     = OpenLibrary("gadgets/integer.gadget", 44)))
  318.                        rq("OpenLibrary(\"gadgets/integer.gadget\") failed!");
  319.     if (!(RadioButtonBase = OpenLibrary("gadgets/radiobutton.gadget", 45)))
  320.                        rq("OpenLibrary(\"gadgets/radiobutton.gadget\") (V45) failed!");
  321.     if (!(SpaceBase       = OpenLibrary("gadgets/space.gadget", 44)))
  322.                        rq("OpenLibrary(\"gadgets/space.gadget\") (V44) failed!");
  323.     if (!(IconBase        = OpenLibrary("icon.library", 44)))
  324.                        rq("Need icon.library V44+!");
  325.           BoardsBase      = OpenLibrary("boards.library", 0);
  326.  
  327.     pubscreen[0] = 0;
  328.     NewList(&EmptyList);
  329.     NewList(&FileList);
  330.     for (i = 0; i <= FUNCTIONS; i++)
  331.     {   image[i]  =
  332.         bitmap[i] = NULL;
  333.     }
  334.     if (!(EADataPtr = AllocVec(4096, MEMF_CLEAR | MEMF_PUBLIC)))
  335.     {   rq("Out of memory!");
  336.     }
  337.  
  338.     /* This is done for speed. Even though the Version command *might* be
  339.     resident, or *might* fit entirely into the disk buffers, we shouldn't
  340.     count on this being the case. So we copy the Version command into RAM:. */
  341.  
  342.     NilHandle = Open("NIL:", MODE_NEWFILE);
  343.     if (NilHandle)
  344.     {   if (!SystemTags("C:Copy C:Version RAM: >NIL:", SYS_Output, NilHandle, TAG_DONE))
  345.         {   ram = TRUE;
  346.         }
  347.         if (!SystemTags("C:CPU >T:ReportPlus.temp", SYS_Output, NilHandle, TAG_DONE))
  348.         {   readordie("T:ReportPlus.temp");
  349.             DeleteFile("T:ReportPlus.temp"); /* returns FALSE for failure */
  350.  
  351.             for (i = 0; i <= VLONGFIELD; i++)
  352.             {   if (IOBuffer[i] == LF)
  353.                 {   IOBuffer[i] = 0;
  354.                     break;
  355.             }   }
  356.             strcpy(cpuline, IOBuffer);
  357.         } else
  358.         {   strcpy(cpuline, "?");
  359.         }
  360.         Close(NilHandle);
  361.         NilHandle = NULL;
  362.     } else
  363.     {   strcpy(cpuline, "?");
  364.     }
  365.  
  366.     report_init();     // f1  list init, var init
  367.     aminet_init();     // f2  list init: memory loss?
  368.     iff_init();        // f6  var init
  369.     size_init();       // f8  list init
  370.     files_init();      // f10  pen init, list init
  371.     /* those must be done before we handle CLI arguments */
  372.  
  373.     if (argc) /* started from CLI */
  374.     {   if (!(ArgsPtr = ReadArgs
  375.         (   "PUBSCREEN/K,-N=NOLOGO/S,FUNCTION/N,-I=ICONTYPE/K,"
  376.             "RESET/S,TIMEOUT/S,LUNS/S,SYNC_XFER/S,SLOW_SYNC/S,TAG_QUEUES/S,HOST_ID/K/N,"
  377.             "FILE/F",
  378.             (LONG *) args,
  379.             NULL
  380.     )))
  381.         {   Printf
  382.             (   "Usage: %s [PUBSCREEN <screen>] [-n|NOLOGO] "
  383.                 "[[FUNCTION] <function>] "
  384.                 "[-i|ICONTYPE DISK|DRAWER|TOOL|PROJECT|TRASHCAN|DEVICE|KICKSTART|APPICON] "
  385.                 "[RESET [TIMEOUT] [LUNS] [SYNC_XFER] [SLOW_SYNC] [TAG_QUEUES] [HOST_ID <host_id>]] "
  386.                 "[[FILE] <file(s)...>]]\n",
  387.                 argv[0]
  388.             );
  389.             cleanexit(EXIT_FAILURE);
  390.     }
  391.         if (args[0])
  392.         {   strcpy(pubscreen, (STRPTR) args[0]);
  393.         }
  394.         if (args[1])
  395.         {   logo = FALSE;
  396.         }
  397.         if (args[2])
  398.         {   number = (SLONG) (*((SLONG *) args[2]));
  399.             if (number >= 1 && number <= FUNCTIONS)
  400.             {   page = closer = (number * 10) + 1;
  401.                 shared.function = number;
  402.             } else
  403.             {   Printf("Report+: <function> must be 1-%ld!\n", FUNCTIONS);
  404.                 cleanexit(EXIT_FAILURE);
  405.         }   }
  406.         if (args[3])
  407.         {   if (number != 4)
  408.             {   Printf("%s: <function> must be 4 for this!\n", argv[0]);
  409.                 cleanexit(EXIT_FAILURE);
  410.             }
  411.             if (!stricmp((STRPTR) args[3], "DISK"))
  412.             {   icon.type = WBDISK;
  413.             } elif (!stricmp((STRPTR) args[3], "DRAWER"))
  414.             {   icon.type = WBDRAWER;
  415.             } elif (!stricmp((STRPTR) args[3], "TOOL"))
  416.             {   icon.type = WBTOOL;
  417.             } elif (!stricmp((STRPTR) args[3], "PROJECT"))
  418.             {   icon.type = WBPROJECT;
  419.             } elif (!stricmp((STRPTR) args[3], "TRASHCAN"))
  420.             {   icon.type = WBGARBAGE;
  421.             } elif (!stricmp((STRPTR) args[3], "DEVICE"))
  422.             {   icon.type = WBDEVICE;
  423.             } elif (!stricmp((STRPTR) args[3], "KICKSTART"))
  424.             {   icon.type = WBKICK;
  425.             } elif (!stricmp((STRPTR) args[3], "APPICON"))
  426.             {   icon.type = WBAPPICON;
  427.             } else
  428.             {   Printf("%s: <icontype> must be DISK, DRAWER, TOOL, PROJECT, TRASHCAN, DEVICE, KICKSTART or APPICON!\n", argv[0]);
  429.                 cleanexit(EXIT_FAILURE);
  430.         }   }
  431.         if (args[4] || args[5] || args[6] || args[7] || args[8] || args[9] || args[10])
  432.         {   if (number != 9)
  433.             {   Printf("%s: <function> must be 9 for this!\n", argv[0]);
  434.                 cleanexit(EXIT_FAILURE);
  435.             }
  436.             if (!args[4])
  437.             {   Printf("%s: You need the RESET switch for this!\n", argv[0]);
  438.                 cleanexit(EXIT_FAILURE);
  439.             }
  440.             for (i = 0; i <= 95; i++)
  441.             {   BattBuffer[i] = FALSE;
  442.             }
  443.             BattBuffer[BATTMEM_AMIGA_AMNESIA_ADDR]          =
  444.             BattBuffer[BATTMEM_SHARED_AMNESIA_ADDR]         = TRUE; // these bits are inverted
  445.             if (args[5])
  446.             {   BattBuffer[BATTMEM_SCSI_TIMEOUT_ADDR]       = TRUE;
  447.             } else BattBuffer[BATTMEM_SCSI_TIMEOUT_ADDR]    = FALSE;
  448.             if (args[6])
  449.             {   BattBuffer[BATTMEM_SCSI_LUNS_ADDR]          = TRUE;
  450.             } else BattBuffer[BATTMEM_SCSI_LUNS_ADDR]       = FALSE;
  451.             if (args[7])
  452.             {   BattBuffer[BATTMEM_SCSI_SYNC_XFER_ADDR]     = TRUE;
  453.             } else BattBuffer[BATTMEM_SCSI_SYNC_XFER_ADDR]  = FALSE;
  454.             if (args[8])
  455.             {   BattBuffer[BATTMEM_SCSI_FAST_SYNC_ADDR]     = TRUE;
  456.             } else BattBuffer[BATTMEM_SCSI_FAST_SYNC_ADDR]  = FALSE;
  457.             if (args[9])
  458.             {   BattBuffer[BATTMEM_SCSI_TAG_QUEUES_ADDR]    = TRUE;
  459.             } else BattBuffer[BATTMEM_SCSI_TAG_QUEUES_ADDR] = FALSE;
  460.             if (args[10]) // these bits are inverted
  461.             {   hostid = (SLONG) (*((SLONG *) args[10]));
  462.                 if (hostid < 0 || hostid > 7)
  463.                 {   Printf("%s: <host_id> must be 0-7!\n", argv[0]);
  464.                     cleanexit(EXIT_FAILURE);
  465.                 }
  466.                 BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR]     = (hostid & 4)? 0 : 1;
  467.                 BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR + 1] = (hostid & 2)? 0 : 1;
  468.                 BattBuffer[BATTMEM_SCSI_HOST_ID_ADDR + 2] = (hostid & 1)? 0 : 1;
  469.             }
  470.             if (!BattMemBase)
  471.             {   if (!(BattMemBase = OpenResource(BATTMEMNAME)))
  472.                 {   rq("Can't open battery RAM resource!");
  473.             }   }
  474.             writebatt(FALSE);
  475.             Printf("Done.\n");
  476.             cleanexit(EXIT_SUCCESS);
  477.         }
  478.         if (args[11])
  479.         {   switch(number)
  480.             {
  481.             case 1:
  482.                 strcpy(report.output, (STRPTR) args[11]);
  483.                 loadreport();
  484.             break;
  485.             case 2:
  486.                 strcpy(aminet.output, (STRPTR) args[11]);
  487.                 loadaminet();
  488.             break;
  489.             case 4:
  490.                 strcpy(shared.pathname, (STRPTR) args[11]);
  491.                 if (convert(FALSE))
  492.                 {   Printf("All done.\n");
  493.                 } else
  494.                 {   Printf("No matches!\n");
  495.                 }
  496.                 cleanexit(EXIT_SUCCESS);
  497.             break;
  498.             case 6:
  499.                 strcpy(iff.pathname, (STRPTR) args[11]);
  500.             break;
  501.             case 7:
  502.                 strcpy(shared.pathname, (STRPTR) args[11]);
  503.                 if (convert(FALSE))
  504.                 {   Printf("All done.\n");
  505.                 } else
  506.                 {   Printf("No matches!\n");
  507.                 }
  508.                 cleanexit(EXIT_SUCCESS);
  509.             break;
  510.             case 8:
  511.                 strcpy(size.path, (STRPTR) args[11]);
  512.             break;
  513.             case 10:
  514.                 strcpy(files.basepath, (STRPTR) args[11]);
  515.             break;
  516.             default:
  517.                 Printf("Report+: <function> must be 1-2, 4, 6-8, or 10 for this!\n");
  518.                 cleanexit(EXIT_FAILURE);
  519.             break;
  520.     }   }   }
  521.     else /* started from WB */
  522.     {   WBMsg = (struct WBStartup *) argv;
  523.         WBArg = WBMsg->sm_ArgList; /* head of the arg list */
  524.         for (i = 0; i < WBMsg->sm_NumArgs; i++, WBArg++)
  525.         {   if (WBArg->wa_Lock)
  526.             {   /* something that does not support locks */
  527.                 parsewb();
  528.             } else
  529.             {   /* lock supported; change to the proper directory */
  530.                 OldDir = CurrentDir(WBArg->wa_Lock);
  531.                 parsewb();
  532.                 CurrentDir(OldDir);
  533.             }
  534.             if (i == 1)
  535.             {   ; /* we were started from a project icon, which is
  536.                 currently unsupported */
  537.     }   }   }
  538.  
  539.     strcpy(asldir, "PROGDIR:");
  540.     /* RKM Libraries, p. 59-61: */
  541.     lockscreen();
  542.     if (GetVPModeID(&(ScreenPtr->ViewPort)) == INVALID_ID)
  543.     {   rq("Invalid default public screen mode ID!");
  544.     }
  545.     xsize   = ScreenPtr->Width;
  546.     if (!(VisualInfoPtr = (struct VisualInfo *) GetVisualInfo(ScreenPtr, TAG_DONE)))
  547.     {   rq("Can't get GadTools visual info!");
  548.     }
  549.     unlockscreen();
  550.  
  551.     if (!(MenuPtr = (struct Menu *) CreateMenus(NewMenu, TAG_DONE)))
  552.     {   rq("Can't create menus!");
  553.     }
  554.     if (!(LayoutMenus(MenuPtr, VisualInfoPtr, GTMN_NewLookMenus, TRUE, TAG_DONE)))
  555.     {   rq("Can't lay out menus!");
  556.     }
  557.  
  558.     if (ConfigHandle = (BPTR) Open("PROGDIR:ReportPlus.config", MODE_OLDFILE))
  559.     {   if (Read(ConfigHandle, IOBuffer, 25) != -1)
  560.         {   manuf_config(); //                                         20
  561.             icon_config();  //                                 161718
  562.             iff_config();   //                                       19
  563.             eol_config();   //   0102030405
  564.             size_config();  // 00          06                15          2122  24
  565.             files_config(); //               0708091011121314                23
  566.         }
  567.         Close(ConfigHandle);
  568.         // ConfigHandle = NULL;
  569.     }
  570.  
  571.     while(1)
  572.     {   if (page != 1)
  573.         {   shared.function = page / 10;
  574.         }
  575.         if (page == 1)
  576.             sender();
  577.         elif (page == 11)
  578.             report1();
  579.         elif (page == 12)
  580.             report2();
  581.         elif (page == 21)
  582.             aminet1();
  583.         elif (page == 31)
  584.             acse1();
  585.         elif (page == 32)
  586.             acse2();
  587.         elif (page == 41)
  588.             icon1();
  589.         elif (page == 51)
  590.             manuf1();
  591.         elif (page == 61)
  592.             iff1();
  593.         elif (page == 71)
  594.             eol1();
  595.         elif (page == 81)
  596.             size1();
  597.         elif (page == 91)
  598.             batt1();
  599.         elif (page == 101)
  600.             files1();
  601.         else
  602.         {   /* assert(page == 0); */
  603.             menu();
  604. }   }   }
  605.  
  606. MODULE void menu(void)
  607. {   PERSIST ABOOL       first = TRUE;
  608.     AUTO    struct Hook Hook0Struct;
  609.     AUTO    ULONG       i, tag[2];
  610.     AUTO    LONG        bgpen;
  611.  
  612.     /* Each of these calls to NewObject() loses 32 bytes, for a loss of
  613.        388 bytes. */
  614.  
  615.     if (first)
  616.     {   lockscreen();
  617.         for (i = 0; i < FUNCTIONS; i++)
  618.         {   if (!(image[i] = NewObject
  619.             (   BITMAP_GetClass(), NULL,
  620.                 BITMAP_SourceFile, imagename[i],
  621.                 BITMAP_Width,      35,
  622.                 BITMAP_Height,     32,
  623.                 BITMAP_Screen,     ScreenPtr,
  624.             TAG_END)
  625.             ))
  626.             {   rq("Can't create ReAction image(s)!");
  627.             }
  628.             GetAttr(BITMAP_BitMap, image[i], (ULONG *) &bitmap[i]);
  629.         }
  630.         unlockscreen();
  631.         first = FALSE;
  632.     }
  633.  
  634.     /* PAGE 0 ************************************************************* */
  635.  
  636.     InitHook(&Hook0Struct, Hook0Func, NULL);
  637.  
  638.     lockscreen();
  639.  
  640.     bgpen = FindColor
  641.     (   ScreenPtr->ViewPort.ColorMap,
  642.         0x96969696,
  643.         0x96969696,
  644.         0x96969696,
  645.         -1
  646.     );
  647.  
  648.     if (logo)
  649.     {   tag[0] = LAYOUT_AddImage;
  650.         tag[1] = NewObject
  651.         (   BITMAP_GetClass(), NULL,
  652.             // bitmap tags
  653.             BITMAP_SourceFile, "PROGDIR:images/logo.ilbm",
  654.             BITMAP_Masking,    TRUE,
  655.             BITMAP_Screen,     ScreenPtr,
  656.             TAG_DONE
  657.         );
  658.     } else
  659.     {   tag[0] = TAG_IGNORE;
  660.         tag[1] = NULL;
  661.     }
  662.  
  663.     if (!(WinObject[0] = NewObject(WINDOW_GetClass(), NULL,
  664.         // window tags
  665.         WA_PubScreen,             ScreenPtr,
  666.         WA_ScreenTitle,           TITLEBARTEXT,
  667.         WA_Title,                 "Report+: Main Menu",
  668.         WA_Activate,              TRUE,
  669.         WA_DepthGadget,           TRUE,
  670.         WA_DragBar,               TRUE,
  671.         WA_CloseGadget,           TRUE,
  672.         WA_IDCMP,                 IDCMP_RAWKEY | IDCMP_INTUITICKS,
  673.         WINDOW_IDCMPHook,         &Hook0Struct,
  674.         WINDOW_IDCMPHookBits,     IDCMP_RAWKEY | IDCMP_INTUITICKS,
  675.         WINDOW_MenuStrip,         MenuPtr,
  676.         WINDOW_Position,          WPOS_CENTERSCREEN,
  677.         WINDOW_ParentGroup,       gadgets[GID_0_LY1] =
  678.         NewObject
  679.         (   LAYOUT_GetClass(),         NULL,
  680.             // root-layout tags
  681.             LAYOUT_Orientation,        LAYOUT_ORIENT_VERT,
  682.             LAYOUT_SpaceOuter,         TRUE,
  683.             LAYOUT_DeferLayout,        TRUE,
  684.             LAYOUT_AddChild,
  685.             NewObject
  686.             (   LAYOUT_GetClass(),     NULL,
  687.                 // layout tags
  688.                 LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ,
  689.                 LAYOUT_DeferLayout,    TRUE,
  690.                 LAYOUT_HorizAlignment, LALIGN_CENTER,
  691.                 tag[0],                tag[1],
  692.                 TAG_DONE
  693.             ),
  694.             LAYOUT_AddChild,
  695.             NewObject
  696.             (   LAYOUT_GetClass(), NULL,
  697.                 // layout tags
  698.                 LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ,
  699.                 LAYOUT_DeferLayout,    TRUE,
  700.                 LAYOUT_HorizAlignment, LALIGN_CENTER,
  701.                 LAYOUT_AddImage,
  702.                 NewObject
  703.                 (   LABEL_GetClass(),    NULL,
  704.                     // label tags
  705.                     LABEL_Justification, LJ_CENTRE,
  706.                     LABEL_Text,          "Edit:",
  707.                     TAG_END
  708.                 ),
  709.                 TAG_END
  710.             ),
  711.             CHILD_WeightedHeight,      0,
  712.             LAYOUT_AddChild,
  713.             NewObject
  714.             (   LAYOUT_GetClass(),         NULL,
  715.                 // layout tags
  716.                 LAYOUT_Orientation,        LAYOUT_ORIENT_HORIZ,
  717.                 LAYOUT_DeferLayout,        TRUE,
  718.                 LAYOUT_AddChild,           gadgets[GID_0_BU1] =
  719.                 NewObject
  720.                 (   NULL, "button.gadget",
  721.                     // button tags
  722.                     GA_ID,                 GID_0_BU1,
  723.                     GA_Left,               20,
  724.                     GA_Top,                20,
  725.                     GA_Width,              41,
  726.                     GA_Height,             40,
  727.                     GA_RelVerify,          TRUE,
  728.                     GA_Image,
  729.                     NewObject
  730.                     (   BITMAP_GetClass(),   NULL,
  731.                         // bitmap tags
  732.                         BITMAP_BitMap,       bitmap[1 - 1],
  733.                         BITMAP_Width,        35,
  734.                         BITMAP_Height,       32,
  735.                         TAG_DONE
  736.                     ),
  737.                     BUTTON_BackgroundPen,    bgpen,
  738.                     BUTTON_FillPen,          bgpen,
  739.                     TAG_DONE
  740.                 ),
  741.                 LAYOUT_AddChild,           gadgets[GID_0_BU2] =
  742.                 NewObject
  743.                 (   NULL, "button.gadget",
  744.                     // button tags
  745.                     GA_ID,                 GID_0_BU2,
  746.                     GA_Left,               20,
  747.                     GA_Top,                20,
  748.                     GA_Width,              41,
  749.                     GA_Height,             40,
  750.                     GA_RelVerify,          TRUE,
  751.                     GA_Image,
  752.                     NewObject
  753.                     (   BITMAP_GetClass(),   NULL,
  754.                         // bitmap tags
  755.                         BITMAP_BitMap,       bitmap[2 - 1],
  756.                         BITMAP_Width,        35,
  757.                         BITMAP_Height,       32,
  758.                         TAG_DONE
  759.                     ),
  760.                     BUTTON_BackgroundPen,    bgpen,
  761.                     BUTTON_FillPen,          bgpen,
  762.                     TAG_DONE
  763.                 ),
  764.                 LAYOUT_AddChild,           gadgets[GID_0_BU3] =
  765.                 NewObject
  766.                 (   NULL,                  "button.gadget",
  767.                     GA_ID,                 GID_0_BU3,
  768.                     GA_Left,               20,
  769.                     GA_Top,                20,
  770.                     GA_Width,              41,
  771.                     GA_Height,             40,
  772.                     GA_RelVerify,          TRUE,
  773.                     GA_Image,              NewObject
  774.                     (   BITMAP_GetClass(),   NULL,
  775.                         // bitmap tags
  776.                         BITMAP_BitMap,       bitmap[9 - 1],
  777.                         BITMAP_Width,        35,
  778.                         BITMAP_Height,       32,
  779.                         TAG_DONE
  780.                     ),
  781.                     BUTTON_BackgroundPen,    bgpen,
  782.                     BUTTON_FillPen,          bgpen,
  783.                 TAG_END),
  784.             TAG_END),
  785.             LAYOUT_AddChild,
  786.             NewObject
  787.             (   LAYOUT_GetClass(),         NULL,
  788.                 // layout tags
  789.                 LAYOUT_Orientation,        LAYOUT_ORIENT_HORIZ,
  790.                 LAYOUT_DeferLayout,        TRUE,
  791.                 LAYOUT_AddChild,
  792.                 NewObject
  793.                 (   LAYOUT_GetClass(),         NULL,
  794.                     // layout tags
  795.                     LAYOUT_Orientation,        LAYOUT_ORIENT_VERT,
  796.                     LAYOUT_DeferLayout,        TRUE,
  797.                     LAYOUT_AddChild,
  798.                     NewObject
  799.                     (    LAYOUT_GetClass(),    NULL,
  800.                          // layout tags
  801.                          LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  802.                          LAYOUT_DeferLayout,   TRUE,
  803.                          LAYOUT_HorizAlignment, LALIGN_CENTER,
  804.                          LAYOUT_AddImage,
  805.                          NewObject
  806.                          (   LABEL_GetClass(), NULL,
  807.                              // label tags
  808.                              LABEL_Justification, LJ_CENTRE,
  809.                              LABEL_Text,          "View:",
  810.                              TAG_END
  811.                          ),
  812.                          TAG_DONE
  813.                     ),
  814.                     LAYOUT_AddChild,
  815.                     NewObject
  816.                     (   LAYOUT_GetClass(),         NULL,
  817.                         // layout tags
  818.                         LAYOUT_Orientation,        LAYOUT_ORIENT_HORIZ,
  819.                         LAYOUT_DeferLayout,        TRUE,
  820.                         LAYOUT_AddChild,           gadgets[GID_0_BU4] =
  821.                         NewObject
  822.                         (   NULL,                  "button.gadget",
  823.                             GA_ID,                 GID_0_BU4,
  824.                             GA_Left,               20,
  825.                             GA_Top,                20,
  826.                             GA_Width,              41,
  827.                             GA_Height,             40,
  828.                             GA_RelVerify,          TRUE,
  829.                             GA_Image,              NewObject
  830.                             (   BITMAP_GetClass(),   NULL,
  831.                                 // bitmap tags
  832.                                 BITMAP_BitMap,       bitmap[5 - 1],
  833.                                 BITMAP_Width,        35,
  834.                                 BITMAP_Height,       32,
  835.                                 TAG_DONE
  836.                             ),
  837.                             BUTTON_BackgroundPen,    bgpen,
  838.                             BUTTON_FillPen,          bgpen,
  839.                             TAG_DONE
  840.                         ),
  841.                         LAYOUT_AddChild,           gadgets[GID_0_BU5] =
  842.                         NewObject
  843.                         (   NULL, "button.gadget",
  844.                             // button tags
  845.                             GA_ID,                 GID_0_BU5,
  846.                             GA_Left,               20,
  847.                             GA_Top,                20,
  848.                             GA_Width,              41,
  849.                             GA_Height,             40,
  850.                             GA_RelVerify,          TRUE,
  851.                             GA_Image,              NewObject
  852.                             (   BITMAP_GetClass(),   NULL,
  853.                                 // bitmap tags
  854.                                 BITMAP_BitMap,       bitmap[6 - 1],
  855.                                 BITMAP_Width,        35,
  856.                                 BITMAP_Height,       32,
  857.                                 TAG_DONE
  858.                             ),
  859.                             BUTTON_BackgroundPen,    bgpen,
  860.                             BUTTON_FillPen,          bgpen,
  861.                             TAG_DONE
  862.                         ),
  863.                         TAG_DONE
  864.                     ),
  865.                     TAG_DONE
  866.                 ),
  867.                 LAYOUT_AddChild,
  868.                 NewObject
  869.                 (   LAYOUT_GetClass(),         NULL,
  870.                     // layout tags
  871.                     LAYOUT_Orientation,        LAYOUT_ORIENT_VERT,
  872.                     LAYOUT_DeferLayout,        TRUE,
  873.                     LAYOUT_AddChild,
  874.                     NewObject
  875.                     (    LAYOUT_GetClass(),    NULL,
  876.                          // layout tags
  877.                          LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  878.                          LAYOUT_DeferLayout,   TRUE,
  879.                          LAYOUT_HorizAlignment, LALIGN_CENTER,
  880.                          LAYOUT_AddImage,
  881.                          NewObject
  882.                          (   LABEL_GetClass(), NULL,
  883.                              // label tags
  884.                              LABEL_Justification, LJ_CENTRE,
  885.                              LABEL_Text,          "Process:",
  886.                          TAG_END),
  887.                     TAG_END),
  888.                     CHILD_WeightedHeight,      0,
  889.                     LAYOUT_AddChild,
  890.                     NewObject
  891.                     (   LAYOUT_GetClass(),         NULL,
  892.                         LAYOUT_Orientation,        LAYOUT_ORIENT_HORIZ,
  893.                         LAYOUT_DeferLayout,        TRUE,
  894.                         LAYOUT_HorizAlignment,     LALIGN_CENTER,
  895.                         LAYOUT_AddChild,           gadgets[GID_0_BU6] =
  896.                         NewObject
  897.                         (   NULL, "button.gadget",
  898.                             // button tags
  899.                             GA_ID,                 GID_0_BU6,
  900.                             GA_Left,               20,
  901.                             GA_Top,                20,
  902.                             GA_Width,              41,
  903.                             GA_Height,             40,
  904.                             GA_RelVerify,          TRUE,
  905.                             GA_Image,              NewObject
  906.                             (   BITMAP_GetClass(),   NULL,
  907.                                 BITMAP_BitMap,       bitmap[4 - 1],
  908.                                 BITMAP_Width,        35,
  909.                                 BITMAP_Height,       32,
  910.                                 TAG_DONE
  911.                             ),
  912.                             BUTTON_BackgroundPen,    bgpen,
  913.                             BUTTON_FillPen,          bgpen,
  914.                         TAG_DONE),
  915.                         LAYOUT_AddChild,           gadgets[GID_0_BU7] =
  916.                         NewObject
  917.                         (   NULL, "button.gadget",
  918.                             // button tags
  919.                             GA_ID,                 GID_0_BU7,
  920.                             GA_Left,               20,
  921.                             GA_Top,                20,
  922.                             GA_Width,              41,
  923.                             GA_Height,             40,
  924.                             GA_RelVerify,          TRUE,
  925.                             GA_Image,              NewObject
  926.                             (   BITMAP_GetClass(),   NULL,
  927.                                 // bitmap tags
  928.                                 BITMAP_BitMap,       bitmap[7 - 1],
  929.                                 BITMAP_Width,        35,
  930.                                 BITMAP_Height,       32,
  931.                                 TAG_DONE
  932.                             ),
  933.                             BUTTON_BackgroundPen,    bgpen,
  934.                             BUTTON_FillPen,          bgpen,
  935.                         TAG_DONE),
  936.                     TAG_DONE),
  937.                 TAG_DONE),
  938.             TAG_DONE),
  939.             LAYOUT_AddChild,
  940.             NewObject
  941.             (   LAYOUT_GetClass(),         NULL,
  942.                 // layout tags
  943.                 LAYOUT_Orientation,        LAYOUT_ORIENT_HORIZ,
  944.                 LAYOUT_DeferLayout,        TRUE,
  945.                 LAYOUT_AddChild,
  946.                 NewObject
  947.                 (   LAYOUT_GetClass(),         NULL,
  948.                     // layout tags
  949.                     LAYOUT_Orientation,        LAYOUT_ORIENT_VERT,
  950.                     LAYOUT_DeferLayout,        TRUE,
  951.                     LAYOUT_AddChild,
  952.                     NewObject
  953.                     (    LAYOUT_GetClass(),       NULL,
  954.                          // layout tags
  955.                          LAYOUT_Orientation,      LAYOUT_ORIENT_HORIZ,
  956.                          LAYOUT_DeferLayout,      TRUE,
  957.                          LAYOUT_HorizAlignment,   LALIGN_CENTER,
  958.                          LAYOUT_AddImage,
  959.                          NewObject
  960.                          (   LABEL_GetClass(),    NULL,
  961.                              // label tags
  962.                              LABEL_Justification, LJ_CENTRE,
  963.                              LABEL_Text,          "Report:",
  964.                              TAG_END
  965.                          ),
  966.                          TAG_DONE
  967.                     ),
  968.                     LAYOUT_AddChild,
  969.                     NewObject
  970.                     (   LAYOUT_GetClass(),         NULL,
  971.                         // layout tags
  972.                         LAYOUT_Orientation,        LAYOUT_ORIENT_HORIZ,
  973.                         LAYOUT_DeferLayout,        TRUE,
  974.                         LAYOUT_AddChild,           gadgets[GID_0_BU8] =
  975.                         NewObject
  976.                         (   NULL, "button.gadget",
  977.                             // button tags
  978.                             GA_ID,                 GID_0_BU8,
  979.                             GA_Left,               20,
  980.                             GA_Top,                20,
  981.                             GA_Width,              41,
  982.                             GA_Height,             40,
  983.                             GA_RelVerify,          TRUE,
  984.                             GA_Image,              NewObject
  985.                             (   BITMAP_GetClass(),   NULL,
  986.                                 // bitmap tags
  987.                                 BITMAP_BitMap,       bitmap[8 - 1],
  988.                                 BITMAP_Width,        35,
  989.                                 BITMAP_Height,       32,
  990.                                 TAG_DONE
  991.                             ),
  992.                             BUTTON_BackgroundPen,    bgpen,
  993.                             BUTTON_FillPen,          bgpen,
  994.                             TAG_DONE
  995.                         ),
  996.                         LAYOUT_AddChild,           gadgets[GID_0_BU9] =
  997.                         NewObject
  998.                         (   NULL,                  "button.gadget",
  999.                             // button tags
  1000.                             GA_ID,                 GID_0_BU9,
  1001.                             GA_Left,               20,
  1002.                             GA_Top,                20,
  1003.                             GA_Width,              41,
  1004.                             GA_Height,             40,
  1005.                             GA_RelVerify,          TRUE,
  1006.                             GA_Image,              NewObject
  1007.                             (   BITMAP_GetClass(),   NULL,
  1008.                                 // bitmap tags
  1009.                                 BITMAP_BitMap,       bitmap[10 - 1],
  1010.                                 BITMAP_Width,        35,
  1011.                                 BITMAP_Height,       32,
  1012.                                 TAG_DONE
  1013.                             ),
  1014.                             BUTTON_BackgroundPen,    bgpen,
  1015.                             BUTTON_FillPen,          bgpen,
  1016.                             TAG_DONE
  1017.                         ),
  1018.                         TAG_DONE
  1019.                     ),
  1020.                     TAG_DONE
  1021.                 ),
  1022.                 LAYOUT_AddChild,
  1023.                 NewObject
  1024.                 (   LAYOUT_GetClass(),         NULL,
  1025.                     // layout tags
  1026.                     LAYOUT_Orientation,        LAYOUT_ORIENT_VERT,
  1027.                     LAYOUT_DeferLayout,        TRUE,
  1028.                     LAYOUT_AddChild,
  1029.                     NewObject
  1030.                     (    LAYOUT_GetClass(),    NULL,
  1031.                          // layout tags
  1032.                          LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  1033.                          LAYOUT_DeferLayout,   TRUE,
  1034.                          LAYOUT_HorizAlignment, LALIGN_CENTER,
  1035.                          LAYOUT_AddImage,
  1036.                          NewObject
  1037.                          (   LABEL_GetClass(), NULL,
  1038.                              // label tags
  1039.                              LABEL_Justification, LJ_CENTRE,
  1040.                              LABEL_Text,          "Conduct:",
  1041.                              TAG_END
  1042.                          ),
  1043.                          TAG_DONE
  1044.                     ),
  1045.                     LAYOUT_AddChild,
  1046.                     NewObject
  1047.                     (   LAYOUT_GetClass(),         NULL,
  1048.                         // layout tags
  1049.                         LAYOUT_Orientation,        LAYOUT_ORIENT_HORIZ,
  1050.                         LAYOUT_DeferLayout,        TRUE,
  1051.                         LAYOUT_AddChild,           gadgets[GID_0_BU10] =
  1052.                         NewObject
  1053.                         (   NULL, "button.gadget",
  1054.                             // button tags
  1055.                             GA_ID,                 GID_0_BU10,
  1056.                             GA_Left,               20,
  1057.                             GA_Top,                20,
  1058.                             GA_Width,              41,
  1059.                             GA_Height,             40,
  1060.                             GA_RelVerify,          TRUE,
  1061.                             GA_Image,              NewObject
  1062.                             (   BITMAP_GetClass(),   NULL,
  1063.                                 // bitmap tags
  1064.                                 BITMAP_BitMap,       bitmap[3 - 1],
  1065.                                 BITMAP_Width,        35,
  1066.                                 BITMAP_Height,       32,
  1067.                                 TAG_DONE
  1068.                             ),
  1069.                             BUTTON_BackgroundPen,  bgpen,
  1070.                             BUTTON_FillPen,        bgpen,
  1071.                             TAG_DONE
  1072.                         ),
  1073.                         TAG_DONE
  1074.                     ),
  1075.                     TAG_DONE
  1076.                 ),
  1077.                 TAG_DONE
  1078.             ),
  1079.             LAYOUT_AddChild,          gadgets[GID_0_ST1] =
  1080.             NewObject
  1081.             (   STRING_GetClass(),    NULL,
  1082.                 // string tags
  1083.                 GA_ID,                GID_0_ST1,
  1084.                 GA_ReadOnly,          TRUE,
  1085.                 STRINGA_TextVal,      TITLEBARTEXT,
  1086.                 TAG_END
  1087.             ),
  1088.             CHILD_WeightedHeight,     0,
  1089.             TAG_DONE
  1090.         ),
  1091.         TAG_DONE
  1092.     )))
  1093.     {   rq("Can't create ReAction gadgets!");
  1094.     }
  1095.     unlockscreen();
  1096.     openwindow();
  1097.     loop();
  1098.     closewindow();
  1099. }
  1100.  
  1101. AGLOBAL void cleanexit(SBYTE rc)
  1102. {   BPTR  ConfigHandle;
  1103.     ULONG i;
  1104.  
  1105.     /* The Amiga loses 24 bytes each time ReportPlus is run...
  1106.  
  1107.     ASL requesters are assumed to be already closed. */
  1108.  
  1109.     /* help|about... */
  1110.     if (AboutWindowPtr)
  1111.     {   DisposeObject(AboutWinObject);
  1112.         AboutWindowPtr = AboutWinObject = NULL;
  1113.     }
  1114.  
  1115.     /* all */
  1116.     unlockscreen(); // in case the screen is locked
  1117.     closewindow();
  1118.  
  1119.     if (MenuPtr)
  1120.     {   FreeMenus(MenuPtr);
  1121.         MenuPtr = NULL;
  1122.     }
  1123.     if (VisualInfoPtr)
  1124.     {   FreeVisualInfo(VisualInfoPtr);
  1125.         VisualInfoPtr = NULL;
  1126.     }
  1127.  
  1128.     /* You can't fool around with attached lists, so we close the window
  1129.     before calling these next routines. */
  1130.  
  1131.     report_die();  // f1  clear list
  1132.     aminet_exit(); // f2  clear subdir list
  1133.     aminet_die();  // f2  clear maindir list
  1134.     acse_exit();   // f3  close timer
  1135.     icon_die();    // f4  config data
  1136.     manuf_die();   // f5  config data
  1137.     iff_exit();    // f6  free memory, clear lists, close iffhandles
  1138.     iff_die();     // f6  config data
  1139.     eol_die();     // f7  config data
  1140.     size_exit();   // f8  close filehandles/locks, clear full lists
  1141.     size_die();    // f8  clear empty lists
  1142.     files_exit();  // f10 clear full list, close filehandle
  1143.     files_die();   // f10 clear empty list, config data
  1144.  
  1145.     if (NilHandle)
  1146.     {   Close(NilHandle);
  1147.         NilHandle = NULL;
  1148.     }
  1149.     if (ram && (NilHandle = Open("NIL:", MODE_NEWFILE)))
  1150.     {   if (!SystemTags("Delete RAM:Version", SYS_Output, NilHandle, TAG_DONE))
  1151.         {   ram = FALSE;
  1152.         }
  1153.         Close(NilHandle);
  1154.         NilHandle = NULL;
  1155.     }
  1156.  
  1157.     if (EADataPtr)
  1158.     {   FreeVec(EADataPtr);
  1159.         EADataPtr = NULL;
  1160.     }
  1161.     if (FontPtr)
  1162.     {   CloseFont(FontPtr);
  1163.         FontPtr = NULL;
  1164.     }
  1165.     if (ArgsPtr)
  1166.     {   FreeArgs(ArgsPtr);
  1167.         ArgsPtr = NULL;
  1168.     }
  1169.  
  1170.     /* Dispose the images ourselves as button.gadget doesn't
  1171.      * do this for its GA_Image...
  1172.      */
  1173.  
  1174.     for (i = 0; i <= FUNCTIONS; i++)
  1175.     {   if (image[i])
  1176.         {   DisposeObject(image[i]);
  1177.             image[i] = NULL;
  1178.     }   }
  1179.          
  1180.     if (rc == EXIT_SUCCESS)
  1181.     {   if (ConfigHandle = (BPTR) Open("PROGDIR:ReportPlus.config", MODE_NEWFILE))
  1182.         {   Write(ConfigHandle, IOBuffer, 25);
  1183.             Close(ConfigHandle);
  1184.             // ConfigHandle = NULL;
  1185.     }   }
  1186.  
  1187.     /* ReAction */
  1188.     if (WindowBase)
  1189.     {   CloseLibrary(WindowBase);
  1190.     }
  1191.     if (TextEditorBase)
  1192.     {   CloseLibrary(TextEditorBase);
  1193.     }
  1194.     if (StringBase)
  1195.     {   CloseLibrary(StringBase);
  1196.     }
  1197.     if (SpaceBase)
  1198.     {   CloseLibrary(SpaceBase);
  1199.     }
  1200.     if (ListBrowserBase)
  1201.     {   CloseLibrary(ListBrowserBase);
  1202.     }
  1203.     if (LayoutBase)
  1204.     {   CloseLibrary(LayoutBase);
  1205.     }
  1206.     if (LabelBase)
  1207.     {   CloseLibrary(LabelBase);
  1208.     }
  1209.     if (IntegerBase)
  1210.     {   CloseLibrary(IntegerBase);
  1211.     }
  1212.     if (FuelGaugeBase)
  1213.     {   CloseLibrary(FuelGaugeBase);
  1214.     }
  1215.     if (ChooserBase)
  1216.     {   CloseLibrary(ChooserBase);
  1217.     }
  1218.     if (CheckBoxBase)
  1219.     {   CloseLibrary(CheckBoxBase);
  1220.     }
  1221.     if (ButtonBase)
  1222.     {   CloseLibrary(ButtonBase);
  1223.     }
  1224.     if (BitMapBase)
  1225.     {   CloseLibrary(BitMapBase);
  1226.     }
  1227.  
  1228.     if (BoardsBase)
  1229.         CloseLibrary((struct Library *) BoardsBase);
  1230.     if (IconBase)
  1231.         CloseLibrary((struct Library *) IconBase);
  1232.     if (IFFParseBase)
  1233.         CloseLibrary((struct Library *) IFFParseBase);
  1234.     if (ASLBase)
  1235.         CloseLibrary((struct Library *) ASLBase);
  1236.     if (GadToolsBase)
  1237.         CloseLibrary((struct Library *) GadToolsBase);
  1238.     if (IntuitionBase)
  1239.     {   OpenWorkBench();
  1240.         CloseLibrary((struct Library *) IntuitionBase);
  1241.     }
  1242.  
  1243.     exit(rc); /* End of program. */
  1244. }
  1245.  
  1246. MODULE void clearkybd(void)
  1247. {   struct IntuiMessage* MsgPtr;
  1248.  
  1249.     while (MsgPtr = (struct IntuiMessage *) GT_GetIMsg(MainWindowPtr->UserPort))
  1250.         GT_ReplyIMsg(MsgPtr);
  1251. }
  1252.  
  1253. AGLOBAL void FreeNameNodes(struct List* ListPtr)
  1254. {   /* RKM Libraries, p. 496:
  1255.     
  1256.     "Free the entire list, including the header. The header is not
  1257.     updated as the list is freed. This function demonstrates how to
  1258.     avoid referencing freed memory when deallocating nodes." */
  1259.  
  1260.     struct NameNode *WorkNodePtr, *NextNodePtr;
  1261.     
  1262.     WorkNodePtr = (struct NameNode *) (ListPtr->lh_Head); /* first node */
  1263.     while (NextNodePtr = (struct NameNode *) (WorkNodePtr->nn_Node.ln_Succ))
  1264.     {   FreeMem(WorkNodePtr, sizeof(struct NameNode));
  1265.         WorkNodePtr = NextNodePtr;
  1266.     }
  1267.     NewList(ListPtr);
  1268. }
  1269. AGLOBAL void FreePathnameNodes(struct List* ListPtr)
  1270. {   struct PathnameNode *WorkNodePtr, *NextNodePtr;
  1271.     
  1272.     WorkNodePtr = (struct PathnameNode *) (ListPtr->lh_Head); /* first node */
  1273.     while (NextNodePtr = (struct PathnameNode *) (WorkNodePtr->Node.ln_Succ))
  1274.     {   FreeMem(WorkNodePtr, sizeof(struct PathnameNode));
  1275.         WorkNodePtr = NextNodePtr;
  1276.     }
  1277.     NewList(ListPtr);
  1278. }
  1279. AGLOBAL void helpabout(void)
  1280. {   PERSIST ABOOL       first = TRUE;
  1281.  
  1282.     if (AboutWindowPtr)
  1283.     {   return;
  1284.     }
  1285.  
  1286.     lockscreen();
  1287.     if (first)
  1288.     {   if (!(image[FUNCTIONS] = NewObject
  1289.         (   BITMAP_GetClass(), NULL,
  1290.             BITMAP_SourceFile, imagename[FUNCTIONS],
  1291.             BITMAP_Width,      44,
  1292.             BITMAP_Height,     38,
  1293.             BITMAP_Screen,     ScreenPtr,
  1294.         TAG_DONE)
  1295.         ))
  1296.         {   rq("Can't create ReAction image!");
  1297.         }
  1298.         GetAttr(BITMAP_BitMap, image[FUNCTIONS], (ULONG *) &bitmap[FUNCTIONS]);
  1299.         first = FALSE;
  1300.     }
  1301.  
  1302.     if (!(AboutWinObject = NewObject(WINDOW_GetClass(), NULL,
  1303.         // window tags
  1304.         WA_PubScreen,             ScreenPtr,
  1305.         WA_ScreenTitle,           TITLEBARTEXT,
  1306.         WA_Title,                 "About Report+",
  1307.         WA_Activate,              TRUE,
  1308.         WA_DepthGadget,           TRUE,
  1309.         WA_DragBar,               TRUE,
  1310.         WA_CloseGadget,           TRUE,
  1311.         WINDOW_Position,          WPOS_CENTERSCREEN,
  1312.         WINDOW_ParentGroup,
  1313.         NewObject
  1314.         (   LAYOUT_GetClass(),         NULL,
  1315.             LAYOUT_Orientation,        LAYOUT_ORIENT_HORIZ,
  1316.             LAYOUT_SpaceOuter,         TRUE,
  1317.             LAYOUT_DeferLayout,        TRUE,
  1318.             LAYOUT_AddChild,
  1319.             NewObject
  1320.             (   LAYOUT_GetClass(),     NULL,
  1321.                 // layout tags
  1322.                 LAYOUT_Orientation,    LAYOUT_ORIENT_VERT,
  1323.                 LAYOUT_SpaceOuter,     TRUE,
  1324.                 LAYOUT_DeferLayout,    TRUE,
  1325.                 LAYOUT_VertAlignment,  LALIGN_CENTER,
  1326.                 LAYOUT_AddImage,
  1327.                 NewObject
  1328.                 (   BITMAP_GetClass(),   NULL,
  1329.                     // bitmap tags
  1330.                     BITMAP_BitMap,       bitmap[FUNCTIONS],
  1331.                     BITMAP_Width,        44,
  1332.                     BITMAP_Height,       38,
  1333.                     TAG_DONE
  1334.                 ),
  1335.                 TAG_DONE
  1336.             ),
  1337.             LAYOUT_AddChild,
  1338.             NewObject
  1339.             (   LAYOUT_GetClass(), NULL,
  1340.                 // layout tags
  1341.                 LAYOUT_Orientation,    LAYOUT_ORIENT_VERT,
  1342.                 LAYOUT_SpaceOuter,     TRUE,
  1343.                 LAYOUT_DeferLayout,    TRUE,
  1344.                 LAYOUT_AddChild,
  1345.                 NewObject
  1346.                 (   LAYOUT_GetClass(), NULL,
  1347.                     // layout tags
  1348.                     LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ,
  1349.                     LAYOUT_DeferLayout,    TRUE,
  1350.                     LAYOUT_AddImage,
  1351.                     NewObject
  1352.                     (   LABEL_GetClass(),    NULL,
  1353.                         // label tags
  1354.                         LABEL_Justification, LJ_CENTRE,
  1355.                         LABEL_Text,          TITLEBARTEXT,
  1356.                         TAG_END
  1357.                     ),
  1358.                     TAG_END
  1359.                 ),
  1360.                 LAYOUT_AddChild,
  1361.                 NewObject
  1362.                 (   LAYOUT_GetClass(),       NULL,
  1363.                     LAYOUT_Orientation,      LAYOUT_ORIENT_HORIZ,
  1364.                     LAYOUT_DeferLayout,      TRUE,
  1365.                     LAYOUT_AddImage,
  1366.                     NewObject
  1367.                     (   LABEL_GetClass(),    NULL,
  1368.                         LABEL_Justification, LJ_CENTRE,
  1369.                         LABEL_Text,          "Monday 21 October 2002",
  1370.                     TAG_END),
  1371.                 TAG_END),
  1372.                 LAYOUT_AddChild,
  1373.                 NewObject
  1374.                 (   LAYOUT_GetClass(),       NULL,
  1375.                     LAYOUT_Orientation,      LAYOUT_ORIENT_HORIZ,
  1376.                     LAYOUT_DeferLayout,      TRUE,
  1377.                     LAYOUT_AddImage,
  1378.                     NewObject
  1379.                     (   LABEL_GetClass(),    NULL,
  1380.                         // label tags
  1381.                         LABEL_Justification, LJ_CENTRE,
  1382.                         LABEL_Text,          " ",
  1383.                         TAG_END
  1384.                     ),
  1385.                     TAG_END
  1386.                 ),
  1387.                 LAYOUT_AddChild,
  1388.                 NewObject
  1389.                 (   LAYOUT_GetClass(), NULL,
  1390.                     // layout tags
  1391.                     LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ,
  1392.                     LAYOUT_DeferLayout,    TRUE,
  1393.                     LAYOUT_AddImage,
  1394.                     NewObject
  1395.                     (   LABEL_GetClass(),    NULL,
  1396.                         // label tags
  1397.                         LABEL_Justification, LJ_CENTRE,
  1398.                         LABEL_Text,          "© 2002 Amigan Software",
  1399.                         TAG_END
  1400.                     ),
  1401.                     TAG_END
  1402.                 ),
  1403.                 LAYOUT_AddChild,
  1404.                 NewObject
  1405.                 (   LAYOUT_GetClass(), NULL,
  1406.                     // layout tags
  1407.                     LAYOUT_Orientation,    LAYOUT_ORIENT_HORIZ,
  1408.                     LAYOUT_DeferLayout,    TRUE,
  1409.                     LAYOUT_AddImage,
  1410.                     NewObject
  1411.                     (   LABEL_GetClass(),    NULL,
  1412.                         // label tags
  1413.                         LABEL_Justification, LJ_CENTRE,
  1414.                         LABEL_Text,          "By James R. Jacobs",
  1415.                         TAG_END
  1416.                     ),
  1417.                     TAG_END
  1418.                 ),
  1419.                 TAG_DONE
  1420.             ),
  1421.             TAG_DONE
  1422.         ),
  1423.         TAG_DONE
  1424.     )))
  1425.     {   rq("Can't create ReAction objects!");
  1426.     }
  1427.     unlockscreen();
  1428.  
  1429.     if (!(AboutWindowPtr = (struct Window *) DoMethod((Object *) AboutWinObject, WM_OPEN, NULL)))
  1430.     {   rq("Can't open ReAction window!");
  1431.     }
  1432.     OffMenu(MainWindowPtr, FULLMENUNUM(MN_HELP, IN_ABOUT, NOSUB));
  1433.  
  1434.     // Obtain the window wait signal mask.
  1435.     GetAttr(WINDOW_SigMask, AboutWinObject, &aboutsignal);
  1436. }
  1437.  
  1438. AGLOBAL void closewindow(void)
  1439. {   if (MainWindowPtr)
  1440.     {   clearkybd();
  1441.  
  1442.         OffMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_NEW,    NOSUB));
  1443.         OffMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_OPEN,   NOSUB));
  1444.         OffMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVE,   NOSUB));
  1445.         OffMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVEAS, NOSUB));
  1446.  
  1447.         /* Disposing of the window object will also close the window if it is
  1448.          * already opened, and it will dispose of the layout object attached to it.
  1449.          */
  1450.         DisposeObject(WinObject[shared.function]);
  1451.         WinObject[shared.function] = NULL;
  1452.         MainWindowPtr = NULL;
  1453. }   }
  1454.  
  1455. AGLOBAL ABOOL asl(STRPTR pattern)
  1456. {   struct FileRequester* ASLRqPtr;
  1457.     ABOOL                 success;
  1458.  
  1459.     /* asldir is the directory that the ASL requester will start in. */
  1460.  
  1461.     if (!(ASLRqPtr = AllocAslRequestTags(ASL_FileRequest, ASL_Pattern, pattern, ASL_Window, MainWindowPtr, TAG_DONE)))
  1462.         rq("Can't create ASL request!");
  1463.     if
  1464.     (   AslRequestTags(ASLRqPtr, ASL_Dir, asldir, ASL_Hail, "Report+ file selector", ASL_FuncFlags, FILF_PATGAD, TAG_DONE)
  1465.      && *(ASLRqPtr->rf_File) != 0
  1466.     )
  1467.     {   strcpy(asldir, ASLRqPtr->rf_Dir);
  1468.         strcpy(aslresult, ASLRqPtr->rf_Dir);
  1469.         if (!AddPart(aslresult, ASLRqPtr->rf_File, PATHNAMEFIELD))
  1470.         {   FreeAslRequest(ASLRqPtr);
  1471.             rq("Can't add filename to pathname!");
  1472.         }
  1473.         success = TRUE;
  1474.     } else
  1475.     {   // either the user chose Cancel, or clicked OK with an empty filename
  1476.         strcpy(aslresult, "");
  1477.         success = FALSE;
  1478.     }
  1479.     // assert(ASLRqPtr);
  1480.     FreeAslRequest(ASLRqPtr);
  1481.     return(success);
  1482. }
  1483.  
  1484. AGLOBAL void loop(void)
  1485. {   SWORD oldpage = page;
  1486.     UWORD code;
  1487.     ULONG result;
  1488.  
  1489.     closer = page;
  1490.     done = FALSE;
  1491.     while (page == oldpage && !done)
  1492.     {   if (AboutWindowPtr)
  1493.         {   about_loop();
  1494.         } else
  1495.         {   if ((Wait(signal | SIGBREAKF_CTRL_C)) & SIGBREAKF_CTRL_C)
  1496.             {   done = TRUE;
  1497.                 /* should we clear the Ctrl-C signal? */
  1498.         }   }
  1499.         while ((result = DoMethod(WinObject[shared.function], WM_HANDLEINPUT, &code)) != WMHI_LASTMSG)
  1500.         {   switch (result & WMHI_CLASSMASK)
  1501.             {
  1502.             case WMHI_MENUPICK:
  1503.                 handlemenus(code);
  1504.             break;
  1505.             case WMHI_CLOSEWINDOW:
  1506.                 if (page == 31)
  1507.                 {   acse_closewindow();
  1508.                 } elif (page == 0)
  1509.                 {   cleanexit(EXIT_SUCCESS);
  1510.                 } elif (page == 1)
  1511.                 {   if (shared.function == 1)
  1512.                     {   page = 11;
  1513.                     } else
  1514.                     {   assert(shared.function == 3);
  1515.                         page = 32;
  1516.                 }   }
  1517.                 else page = 0;
  1518.             break;
  1519.             case WMHI_GADGETUP:
  1520.                 if (page == 1)
  1521.                 {   sender_loop(result & WMHI_GADGETMASK);
  1522.                 } else
  1523.                 {   switch(shared.function)
  1524.                     {
  1525.                     case 0:
  1526.                         menu_loop(result & WMHI_GADGETMASK);
  1527.                     break;
  1528.                     case 1:
  1529.                         report_ra_loop(result & WMHI_GADGETMASK);
  1530.                     break;
  1531.                     case 2:
  1532.                         aminet_loop(result & WMHI_GADGETMASK);
  1533.                     break;
  1534.                     case 3:
  1535.                         acse_loop(result & WMHI_GADGETMASK);
  1536.                     break;
  1537.                     case 4:
  1538.                         icon_loop(result & WMHI_GADGETMASK);
  1539.                     break;
  1540.                     case 5:
  1541.                         manuf_loop(result & WMHI_GADGETMASK);
  1542.                     break;
  1543.                     case 6:
  1544.                         iff_loop(result & WMHI_GADGETMASK);
  1545.                     break;
  1546.                     case 7:
  1547.                         eol_loop(result & WMHI_GADGETMASK);
  1548.                     break;
  1549.                     case 8:
  1550.                         size_loop(result & WMHI_GADGETMASK);
  1551.                     break;
  1552.                     case 9:
  1553.                         batt_loop(result & WMHI_GADGETMASK);
  1554.                     break;
  1555.                     case 10:
  1556.                         files_loop(result & WMHI_GADGETMASK);
  1557.                     break;
  1558.                     default:
  1559.                         assert(0);
  1560.                     break;
  1561.                 }   }
  1562.             break;
  1563.             default:
  1564.             break;
  1565. }   }   }   }
  1566.  
  1567. AGLOBAL ABOOL readin(STRPTR pathname)
  1568. {   BPTR FileHandle;
  1569.  
  1570.     if (!(FileHandle = (BPTR) Open(pathname, MODE_OLDFILE)))
  1571.         return FALSE;
  1572.     if (Read(FileHandle, IOBuffer, LONGESTFIELD) == -1)
  1573.     /* Limitation: the whole file must be < 16K */
  1574.     {   Close(FileHandle);
  1575.         return FALSE;
  1576.     }
  1577.     Close(FileHandle);
  1578.     return TRUE;
  1579. }
  1580.  
  1581. AGLOBAL void writeout(STRPTR pathname)
  1582. {   BPTR FileHandle;
  1583.  
  1584.     if (!(FileHandle = (BPTR) Open(pathname, MODE_NEWFILE)))
  1585.         rq("Can't open file for writing!");
  1586.     if (Write(FileHandle, IOBuffer, strlen(IOBuffer)) == -1)
  1587.     {   Close(FileHandle);
  1588.         rq("Can't write to file!");
  1589.     }
  1590.     Close(FileHandle);
  1591. }
  1592.  
  1593. AGLOBAL void rq(STRPTR text)
  1594. {   EasyStruct.es_TextFormat = text;
  1595.     EasyRequest(MainWindowPtr, &EasyStruct, NULL);
  1596.  
  1597.     cleanexit(EXIT_FAILURE);
  1598. }
  1599.  
  1600. AGLOBAL void readordie(STRPTR pathname)
  1601. {   BPTR LocalFileHandle;
  1602.  
  1603.     if (!(LocalFileHandle = (BPTR) Open(pathname, MODE_OLDFILE)))
  1604.         rq("Can't open file for reading!");
  1605.     if (Read(LocalFileHandle, IOBuffer, LONGESTFIELD) == -1)
  1606.     {   Close(LocalFileHandle);
  1607.         rq("Can't read file!");
  1608.     }
  1609.     Close(LocalFileHandle);
  1610. }
  1611.  
  1612. MODULE void parsewb(void)
  1613. {   struct DiskObject* DiskObject;
  1614.     STRPTR*            ToolArray;
  1615.     STRPTR             s;
  1616.  
  1617.     if ((*WBArg->wa_Name) && (DiskObject = GetDiskObject(WBArg->wa_Name)))
  1618.     {   ToolArray = (STRPTR *) DiskObject->do_ToolTypes;
  1619.  
  1620.         if (s = FindToolType((CONST_STRPTR *) ToolArray, "PUBSCREEN"))
  1621.             strcpy(pubscreen, s);
  1622.         if (s = FindToolType((CONST_STRPTR *) ToolArray, "NOLOGO"))
  1623.             logo = FALSE;
  1624.         if (s = FindToolType((CONST_STRPTR *) ToolArray, "ICONTYPE"))
  1625.         {   if (MatchToolValue(s, "DISK"))
  1626.             {   icon.type = WBDISK - 1;
  1627.             } elif (MatchToolValue(s, "DRAWER"))
  1628.             {   icon.type = WBDRAWER - 1;
  1629.             } elif (MatchToolValue(s, "TOOL"))
  1630.             {   icon.type = WBTOOL - 1;
  1631.             } elif (MatchToolValue(s, "PROJECT"))
  1632.             {   icon.type = WBPROJECT - 1;
  1633.             } elif (MatchToolValue(s, "TRASHCAN"))
  1634.             {   icon.type = WBGARBAGE - 1;
  1635.             } elif (MatchToolValue(s, "DEVICE"))
  1636.             {   icon.type = WBDEVICE - 1;
  1637.             } elif (MatchToolValue(s, "KICKSTART"))
  1638.             {   icon.type = WBKICK - 1;
  1639.             } elif (MatchToolValue(s, "APPICON"))
  1640.             {   icon.type = WBAPPICON - 1;
  1641.         }   }
  1642.         if (s = FindToolType((CONST_STRPTR *) ToolArray, "FUNCTION"))
  1643.         {   if (MatchToolValue(s, "1"))
  1644.                 page = 11;
  1645.             elif (MatchToolValue(s, "2"))
  1646.                 page = 21;
  1647.             elif (MatchToolValue(s, "3"))
  1648.                 page = 31;
  1649.             elif (MatchToolValue(s, "4"))
  1650.                 page = 41;
  1651.             elif (MatchToolValue(s, "5"))
  1652.                 page = 51;
  1653.             elif (MatchToolValue(s, "6"))
  1654.                 page = 61;
  1655.             elif (MatchToolValue(s, "7"))
  1656.                 page = 71;
  1657.             elif (MatchToolValue(s, "8"))
  1658.                 page = 81;
  1659.             elif (MatchToolValue(s, "9"))
  1660.                 page = 91;
  1661.             elif (MatchToolValue(s, "10"))
  1662.                 page = 101;
  1663.         }
  1664.         FreeDiskObject(DiskObject);
  1665. }   }
  1666.  
  1667. AGLOBAL void getdate(void)
  1668. {   struct DateTime DateTime;
  1669.  
  1670.     DateTime.dat_Format  = FORMAT_DOS;
  1671.     DateTime.dat_Flags   = NULL;
  1672.     DateTime.dat_StrDay  = weekdaystring;
  1673.     DateTime.dat_StrDate = datestring;
  1674.     DateTime.dat_StrTime = timestring;
  1675.  
  1676.     DateStamp(&(DateTime.dat_Stamp));
  1677.     if (!DateToStr(&DateTime))
  1678.         rq("Can't convert date!");
  1679. }
  1680.  
  1681. AGLOBAL void AddNameToTail(struct List* ListPtr, STRPTR name)
  1682. {   /* RKM Libraries, p. 496:
  1683.     
  1684.     "Allocate a NameNode structure, copy the given name into the
  1685.     structure, then add it [to] the...list." */
  1686.  
  1687.     struct NameNode* NameNodePtr;
  1688.  
  1689.     if (!(NameNodePtr = AllocMem(sizeof(struct NameNode), MEMF_CLEAR)))
  1690.         rq("Out of memory!");
  1691.     strcpy(NameNodePtr->nn_Data, name);
  1692.     NameNodePtr->nn_Node.ln_Name = NameNodePtr->nn_Data;
  1693.     NameNodePtr->nn_Node.ln_Type = NT_USER;
  1694.     NameNodePtr->nn_Node.ln_Pri  = 0;
  1695.     AddTail((struct List *) ListPtr, (struct Node *) NameNodePtr);
  1696. }
  1697. AGLOBAL void AddPathnameNode(struct List* ListPtr, STRPTR name)
  1698. {   struct PathnameNode* PathnameNodePtr;
  1699.  
  1700.     if (!(PathnameNodePtr = AllocMem(sizeof(struct PathnameNode), MEMF_CLEAR)))
  1701.         rq("Out of memory!");
  1702.     strcpy(PathnameNodePtr->pathname, name);
  1703.     PathnameNodePtr->Node.ln_Name = NULL;
  1704.     PathnameNodePtr->Node.ln_Type = NT_USER;
  1705.     PathnameNodePtr->Node.ln_Pri  = 0;
  1706.     AddTail((struct List *) ListPtr, (struct Node *) PathnameNodePtr);
  1707. }
  1708.  
  1709. AGLOBAL void append(STRPTR pathname)
  1710. {   BPTR FileHandle;
  1711.  
  1712.     if (!(FileHandle = (BPTR) Open(pathname, MODE_READWRITE)))
  1713.         rq("Can't open file for appending!");
  1714.     Seek(FileHandle, 0, OFFSET_END);
  1715.     if (Write(FileHandle, IOBuffer, strlen(IOBuffer)) == -1)
  1716.     {   Close(FileHandle);
  1717.         rq("Can't append to file!");
  1718.     }
  1719.     if (!Close(FileHandle))
  1720.         rq("Can't close appended file!");
  1721. }
  1722.  
  1723. MODULE void about_loop(void)
  1724. {   UWORD code;
  1725.     ULONG result;
  1726.     ABOOL localdone = FALSE;
  1727.  
  1728.     // Processes any messages for the About... window.
  1729.  
  1730.     if ((Wait(aboutsignal | SIGBREAKF_CTRL_C)) & SIGBREAKF_CTRL_C)
  1731.     {   localdone = TRUE;
  1732.         /* should we clear the Ctrl-C signal? */
  1733.     }
  1734.     while ((result = DoMethod(AboutWinObject, WM_HANDLEINPUT, &code)) != WMHI_LASTMSG)
  1735.     {   switch (result & WMHI_CLASSMASK)
  1736.         {
  1737.         case WMHI_MENUPICK:
  1738.             ; // handlemenus(code);
  1739.         break;
  1740.         case WMHI_CLOSEWINDOW:
  1741.             localdone = TRUE;
  1742.         break;
  1743.         default:
  1744.         break;
  1745.     }   }
  1746.  
  1747.     if (localdone)
  1748.     {   DisposeObject(AboutWinObject);
  1749.         AboutWindowPtr = AboutWinObject = NULL;
  1750.         OnMenu(MainWindowPtr, FULLMENUNUM(MN_HELP, IN_ABOUT, NOSUB));
  1751. }   }
  1752.  
  1753. AGLOBAL void parse(STRPTR terminator)
  1754. {   ABOOL done = FALSE;
  1755.     ULONG dest = 0; // index in destination string
  1756.  
  1757.     while (!done)
  1758.     {   if (IOBuffer[offset] != CR)
  1759.         {   string[dest] = IOBuffer[offset];
  1760.         }
  1761.         if (!strncmp(&IOBuffer[offset], terminator, strlen(terminator)))
  1762.         {   string[dest] = 0;
  1763.             done = TRUE;
  1764.             offset += strlen(terminator);
  1765.         } elif (offset > strlen(IOBuffer)) // we are past the end of the buffer
  1766.         {   string[0] = 0;
  1767.             done = TRUE;
  1768.         } else
  1769.         {   offset++;
  1770.             if (IOBuffer[offset] != CR)
  1771.             {   dest++;
  1772. }   }   }   }
  1773.  
  1774. AGLOBAL void parsetoend(void)
  1775. {   ABOOL done      = FALSE;
  1776.     ULONG suboffset = 0;
  1777.  
  1778.     while (!done)
  1779.     {   string[suboffset] = IOBuffer[offset];
  1780.         if (offset > strlen(IOBuffer))
  1781.         {   /* EOF */
  1782.             string[suboffset] = 0;
  1783.             done = TRUE;
  1784.         } else
  1785.         {   offset++;
  1786.             suboffset++;
  1787. }   }   }
  1788.  
  1789. AGLOBAL ABOOL saveasl(STRPTR message, STRPTR pattern)
  1790. {   struct FileRequester* ASLRqPtr;
  1791.     TEXT                  tempstring[VLONGFIELD + 1];
  1792.     ABOOL                 success;
  1793.  
  1794.     strcpy(tempstring, "Report+: ");
  1795.     strcat(tempstring, message);
  1796.  
  1797.     if (!(ASLRqPtr = AllocAslRequestTags(ASL_FileRequest, ASL_Pattern, "~(#?.info)", ASL_Window, MainWindowPtr, TAG_DONE)))
  1798.         rq("Can't create ASL request!");
  1799.     if
  1800.     (   AslRequestTags(ASLRqPtr, ASL_Dir, asldir, ASL_Hail, tempstring, ASL_FuncFlags, FILF_PATGAD | FILF_SAVE, TAG_DONE)
  1801.      && *(ASLRqPtr->rf_File) != 0
  1802.     )
  1803.     {   strcpy(asldir, ASLRqPtr->rf_Dir);
  1804.         strcpy(aslresult, ASLRqPtr->rf_Dir);
  1805.         if (!AddPart(aslresult, ASLRqPtr->rf_File, PATHNAMEFIELD))
  1806.         {   FreeAslRequest(ASLRqPtr);
  1807.             rq("Can't add filename to pathname!");
  1808.         }
  1809.         success = TRUE;
  1810.     } else
  1811.     {   strcpy(aslresult, "");
  1812.         success = FALSE;
  1813.     }
  1814.     // assert(ASLRqPtr);
  1815.     FreeAslRequest(ASLRqPtr);
  1816.     return(success);
  1817. }
  1818.  
  1819. AGLOBAL void handlemenus(UWORD code)
  1820. {   /* struct MenuItem* ItemPtr; */
  1821.  
  1822.     if (code != MENUNULL) /* while (code != MENUNULL) */
  1823.     {   /* ItemPtr = ItemAddress(MenuPtr, code); */
  1824.         switch (MENUNUM(code))
  1825.         {
  1826.         case MN_PROJECT:
  1827.             switch (ITEMNUM(code))
  1828.             {
  1829.             case IN_NEW:
  1830.                 if (shared.function == 1)
  1831.                     newreport(TRUE);
  1832.                 elif (shared.function == 2)
  1833.                     newaminet(TRUE);
  1834.             break;
  1835.             case IN_OPEN:
  1836.                 if (shared.function == 1)
  1837.                     openreport();
  1838.                 elif (shared.function == 2)
  1839.                     openaminet();
  1840.                 elif (shared.function == 9)
  1841.                     batt_open();
  1842.             break;
  1843.             case IN_SAVE:
  1844.                 if (shared.function == 1)
  1845.                     savereport(FALSE);
  1846.                 elif (shared.function == 2)
  1847.                     saveaminet(FALSE);
  1848.                 elif (shared.function == 9)
  1849.                     batt_save(FALSE);
  1850.             break;
  1851.             case IN_SAVEAS:
  1852.                 if (shared.function == 1)
  1853.                     savereport(TRUE);
  1854.                 elif (shared.function == 2)
  1855.                     saveaminet(TRUE);
  1856.                 elif (shared.function == 9)
  1857.                     batt_save(TRUE);
  1858.             break;
  1859.             case IN_QUIT:
  1860.                 cleanexit(EXIT_SUCCESS);
  1861.             break;
  1862.             default:
  1863.             break;
  1864.             }
  1865.         break;
  1866.         case MN_HELP:
  1867.             switch (ITEMNUM(code))
  1868.             {
  1869.             case IN_ABOUT:
  1870.                 helpabout();
  1871.             break;
  1872.             default:
  1873.             break;
  1874.             }
  1875.         break;
  1876.         default:
  1877.         break;
  1878.         }
  1879.         /* Doing things the above way disables multi-selection,
  1880.         but prevents `endless selection'.
  1881.         code = ItemPtr->NextSelect; */
  1882. }   }
  1883.  
  1884. AGLOBAL void lockscreen(void)
  1885. {   if (pubscreen[0])
  1886.     {   if (!(ScreenPtr = LockPubScreen(pubscreen)))
  1887.         {   rq("Can't lock specified public screen!");
  1888.     }   }
  1889.     else
  1890.     {   if (!(ScreenPtr = LockPubScreen(NULL)))
  1891.         {   rq("Can't lock default public screen!");
  1892. }   }   }
  1893. AGLOBAL void unlockscreen(void)
  1894. {   if (ScreenPtr)
  1895.     {   if (pubscreen[0])
  1896.         {   UnlockPubScreen(pubscreen, ScreenPtr);
  1897.             ScreenPtr = NULL;
  1898.         } else
  1899.         {   UnlockPubScreen(NULL, ScreenPtr);
  1900.             ScreenPtr = NULL;
  1901. }   }   }
  1902.  
  1903. MODULE void eachwildcard(STRPTR subpattern, ABOOL gui)
  1904. {   struct AnchorPath* AnchorPathPtr;
  1905.     BPTR               OldDir;
  1906.     BOOL               result;
  1907.     ABOOL              done;
  1908.  
  1909.     shared.thisfile[0] = 0;
  1910.     // AnchorPathPtr must be longword aligned
  1911.     if (!(AnchorPathPtr = AllocMem(sizeof(struct AnchorPath), MEMF_ANY | MEMF_PUBLIC)))
  1912.     {   return;
  1913.     }
  1914.  
  1915.     /* We can't do the processing of the files until we have finished
  1916.     all of the Match...() calls, due to lock problems. So we build a
  1917.     list of the pathnames. */
  1918.  
  1919.     AnchorPathPtr->ap_BreakBits = NULL;
  1920.     AnchorPathPtr->ap_Flags     = NULL;
  1921.     AnchorPathPtr->ap_Strlen    = 0;
  1922.     result = MatchFirst(subpattern, AnchorPathPtr);
  1923.     if (result == 0) // 0 means success
  1924.     {   OldDir = CurrentDir(AnchorPathPtr->ap_Current->an_Lock);
  1925.         if (!NameFromLock(AnchorPathPtr->ap_Current->an_Lock, shared.thisfile, PATHNAMEFIELD))
  1926.         {   MatchEnd(AnchorPathPtr);
  1927.             return;
  1928.         }
  1929.         if (!AddPart(shared.thisfile, AnchorPathPtr->ap_Info.fib_FileName, PATHNAMEFIELD))
  1930.         {   MatchEnd(AnchorPathPtr);
  1931.             return;
  1932.         }
  1933.         CurrentDir(OldDir);
  1934.         AddPathnameNode(&FileList, shared.thisfile);
  1935.     } elif (result != ERROR_NO_MORE_ENTRIES)
  1936.     {   MatchEnd(AnchorPathPtr);
  1937.         return;
  1938.     }
  1939.  
  1940.     done = FALSE;
  1941.     while (!done)
  1942.     {   result = MatchNext(AnchorPathPtr);
  1943.         if (result == 0)
  1944.         {   OldDir = CurrentDir(AnchorPathPtr->ap_Current->an_Lock);
  1945.             if (!NameFromLock(AnchorPathPtr->ap_Current->an_Lock, shared.thisfile, PATHNAMEFIELD))
  1946.             {   MatchEnd(AnchorPathPtr);
  1947.                 return;
  1948.             }
  1949.             if (!AddPart(shared.thisfile, AnchorPathPtr->ap_Info.fib_FileName, PATHNAMEFIELD))
  1950.             {   MatchEnd(AnchorPathPtr);
  1951.                 return;
  1952.             }
  1953.             CurrentDir(OldDir);
  1954.             AddPathnameNode(&FileList, shared.thisfile);
  1955.         } elif (result != ERROR_NO_MORE_ENTRIES)
  1956.         {   MatchEnd(AnchorPathPtr);
  1957.             return;
  1958.         } else done = TRUE;
  1959.     }
  1960.     MatchEnd(AnchorPathPtr);
  1961.     FreeMem(AnchorPathPtr, sizeof(struct AnchorPath));
  1962. }
  1963.  
  1964. AGLOBAL void multiasl(STRPTR pattern)
  1965. {   struct FileRequester* ASLRqPtr;
  1966.     ULONG                 i;
  1967.     TEXT                  quotestring[2];
  1968.  
  1969.     quotestring[0] = QUOTE;
  1970.     quotestring[1] = 0;
  1971.  
  1972.     /* It would also be good to correctly
  1973.     handle selection of directories. */
  1974.  
  1975.     if (!(ASLRqPtr = AllocAslRequestTags(ASL_FileRequest, ASL_Pattern, pattern, ASL_Window, MainWindowPtr, TAG_DONE)))
  1976.         rq("Can't create ASL request!");
  1977.     if (AslRequestTags(ASLRqPtr, ASL_Dir, asldir, ASL_Hail, "Report+ file multiselector", ASL_FuncFlags, FILF_PATGAD | FILF_MULTISELECT, TAG_DONE) && *(ASLRqPtr->rf_File) != 0)
  1978.     {   if (ASLRqPtr->rf_NumArgs)
  1979.         {   /* rf_ArgList is an array of WBArg structures. Each entry in
  1980.             this array corresponds to one of the files the user selected
  1981.             (in alphabetical order). The user multiselected; step through
  1982.             the list of selected files. */
  1983.             strcpy(asldir, ASLRqPtr->rf_Dir);
  1984.             strcpy(shared.pathname, quotestring);
  1985.             strcat(shared.pathname, ASLRqPtr->rf_Dir);
  1986.             if (!AddPart(shared.pathname, (ASLRqPtr->rf_ArgList)[0].wa_Name, PATHNAMEFIELD))
  1987.             {   FreeAslRequest(ASLRqPtr);
  1988.                 rq("Can't add filename to pathname!");
  1989.             }
  1990.             strcat(shared.pathname, quotestring);
  1991.             strcat(shared.pathname, " ");
  1992.             for (i = 1; i < ASLRqPtr->rf_NumArgs; i++)
  1993.             {   strcat(shared.pathname, quotestring);
  1994.                 strcat(shared.pathname, ASLRqPtr->rf_Dir);
  1995.                 if (!AddPart(shared.pathname, (ASLRqPtr->rf_ArgList)[i].wa_Name, PATHNAMEFIELD))
  1996.                    rq("Can't add filename to pathname!");
  1997.                 strcat(shared.pathname, quotestring);
  1998.                 if (i < ASLRqPtr->rf_NumArgs - 1)
  1999.                     strcat(shared.pathname, " ");
  2000.         }   }
  2001.         else
  2002.         {   /* The user didn't multiselect; use the normal way to get the
  2003.             filename. */
  2004.  
  2005.             strcpy(asldir, ASLRqPtr->rf_Dir);
  2006.             strcpy(shared.pathname, quotestring);
  2007.             strcat(shared.pathname, ASLRqPtr->rf_Dir);
  2008.             if (!AddPart(shared.pathname, ASLRqPtr->rf_File, PATHNAMEFIELD))
  2009.             {   FreeAslRequest(ASLRqPtr);
  2010.                 rq("Can't add filename to pathname!");
  2011.             }
  2012.             strcat(shared.pathname, quotestring);
  2013.     }   }
  2014.     else
  2015.     {   ; // the user chose Cancel
  2016.     }
  2017.     // assert(ASLRqPtr);
  2018.     FreeAslRequest(ASLRqPtr);
  2019. }
  2020.  
  2021. AGLOBAL void checkabort(ABOOL gui)
  2022. {   ULONG signals, gid, result;
  2023.     UWORD code;
  2024.  
  2025.     /* OK, we've just finished operating on that file. Now before we */
  2026.     /* start on the next one, check whether the user still wants to... */
  2027.     signals = SetSignal(0L, 0L);
  2028.     if (signals & SIGBREAKF_CTRL_C)
  2029.     {   stop = TRUE;
  2030.         SetSignal(0L, SIGBREAKF_CTRL_C); /* clear the Ctrl-C signal */
  2031.         if (gui)
  2032.         {   if (shared.function == 7)
  2033.             {   SetGadgetAttrs
  2034.                 (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  2035.                     STRINGA_TextVal, "Aborted by user!",
  2036.                 TAG_DONE);
  2037.             } else
  2038.             {   // assert(shared.function == 4);
  2039.                 SetGadgetAttrs
  2040.                 (   icon_gadgets[GID_4_ST2], MainWindowPtr, NULL,
  2041.                     STRINGA_TextVal, "Aborted by user!",
  2042.                 TAG_DONE);
  2043.         }   }
  2044.         else
  2045.         {   Printf("Aborted by user!\n");
  2046.             Flush(Output());
  2047.     }   }
  2048.  
  2049.     while ((result = DoMethod(WinObject[shared.function], WM_HANDLEINPUT, &code)) != WMHI_LASTMSG)
  2050.     {   switch (result & WMHI_CLASSMASK)
  2051.         {
  2052.         case WMHI_MENUPICK:
  2053.             ; /* handlemenus(code); */
  2054.         break;
  2055.         case WMHI_CLOSEWINDOW:
  2056.             done = quit = TRUE;
  2057.         break;
  2058.         case WMHI_GADGETUP:
  2059.             gid = result & WMHI_GADGETMASK;
  2060.             if
  2061.             (   (shared.function == 4 && gid == GID_4_BU4)
  2062.              || (shared.function == 7 && gid == GID_7_BU4)
  2063.             )
  2064.             {   stop = TRUE;
  2065.             }
  2066.         break;
  2067.         default:
  2068.         break;
  2069. }   }   }
  2070.  
  2071. AGLOBAL ABOOL convert(ABOOL gui)
  2072. {   ULONG        i, j, length;
  2073.     ABOOL        letters, /* are we in letters (TRUE) or whitespace (FALSE)? */
  2074.                  quoted;  /* are we quoted (TRUE) or unquoted (FALSE)? */
  2075.     struct PathnameNode* NodePtr;
  2076.  
  2077.     /* At this point we have a list of pathnames, separated by spaces and
  2078.     NULL-terminated. If they came from ASL, they will be quoted, otherwise,
  2079.     they may not. This is the raw input; it can contain anything,
  2080.     including wildcards.
  2081.  
  2082.     shared.pathname: the actual contents of the string gadget.
  2083.     shared.thatfile: each file that we pass to eachwildcard().
  2084.     shared.thisfile: each file that we pass for conversion. */
  2085.  
  2086.     stop = letters = quoted = FALSE;
  2087.     length = strlen(shared.pathname);
  2088.     j = 0;
  2089.  
  2090.     for (i = 0; i < length; i++)
  2091.     {   if (!stop)
  2092.         {   if (shared.pathname[i] == ' ' && letters && !quoted)
  2093.             {   /* if we're unquoted and have a space */
  2094.                 shared.thatfile[j] = 0; /* then NULL-terminate the pathname */
  2095.                 eachwildcard(shared.thatfile, gui);
  2096.                 j = 0;
  2097.                 letters = FALSE;
  2098.             } elif (shared.pathname[i] == QUOTE)
  2099.             {   if (!letters && !quoted)
  2100.                 {   letters = TRUE; /* we're in letters */
  2101.                     quoted = TRUE; /* it's a quote */
  2102.                 } elif (letters && quoted)
  2103.                 {   quoted = FALSE; /* it's an unquote */
  2104.             }   }
  2105.             else
  2106.             {   shared.thatfile[j++] = shared.pathname[i];
  2107.                 letters = TRUE; /* we're in letters */
  2108.     }   }   }
  2109.     /* Now we are at the end. */
  2110.     if (!stop && letters) /* if we're in letters */
  2111.     {   shared.thatfile[j] = 0;
  2112.         /* then it is ended, quoted or not. Although we could */
  2113.         /* report an error condition if there are an odd */
  2114.         /* number of quotes (ie. a missing quote). */
  2115.         eachwildcard(shared.thatfile, gui);
  2116.     }
  2117.  
  2118.     if ((FileList.lh_Head)->ln_Succ) // if the list is non-empty
  2119.     {   // Walk the list
  2120.         for
  2121.         (   NodePtr = FileList.lh_Head;
  2122.             NodePtr->Node.ln_Succ;
  2123.             NodePtr = NodePtr->Node.ln_Succ
  2124.         )
  2125.         {   if (!stop)
  2126.             {   strcpy(shared.thisfile, NodePtr->pathname);
  2127.                 if (shared.function == 7)
  2128.                 {   eolconvert(gui);
  2129.                 } else
  2130.                 {   /* assert(shared.function == 4); */
  2131.                     iconconvert(gui);
  2132.         }   }   }
  2133.         if (FileList.lh_Head->ln_Succ) // if list is non-empty
  2134.         {   FreePathnameNodes(&FileList);
  2135.         }
  2136.         return(TRUE);
  2137.     } else
  2138.     {   return(FALSE);
  2139. }   }
  2140.  
  2141. MODULE void menu_loop(ULONG gid)
  2142. {   switch (gid)
  2143.     {
  2144.     case GID_0_BU1:
  2145.         page = 11;  // bug report
  2146.     break;
  2147.     case GID_0_BU2:
  2148.         page = 21;  // Aminet readme
  2149.     break;
  2150.     case GID_0_BU3:
  2151.         page = 91;  // battery RAM
  2152.     break;
  2153.     case GID_0_BU4:
  2154.         page = 51;  // ID database
  2155.     break;
  2156.     case GID_0_BU5:
  2157.         page = 61;  // IFF FORMs
  2158.     break;
  2159.     case GID_0_BU6:
  2160.         page = 41;  // icons
  2161.     break;
  2162.     case GID_0_BU7:
  2163.         page = 71;  // EOL/tabs
  2164.     break;
  2165.     case GID_0_BU8:
  2166.         page = 81;  // path size
  2167.     break;
  2168.     case GID_0_BU9:
  2169.         page = 101; // system files
  2170.     break;
  2171.     case GID_0_BU10:
  2172.         page = 31;  // ACSE
  2173.     break;
  2174.     default:
  2175.         ; // assert(0);
  2176.     break;
  2177. }   }
  2178.  
  2179. AGLOBAL ULONG Hook0Func(struct Hook *h, VOID *o, VOID *msg)
  2180. {   /* "When the hook is called, the data argument points to the 
  2181.     window object and message argument to the IntuiMessage."
  2182.  
  2183.     These IntuiMessages do not need to be replied to by the appliprog. */
  2184.  
  2185.     AUTO    UWORD code, qual;
  2186.     AUTO    ULONG class, i;
  2187.     AUTO    SWORD mousex, mousey;
  2188.     AUTO    SLONG newover;
  2189.     PERSIST ULONG over = FUNCTIONS;
  2190.  
  2191.     geta4(); // wait till here before doing anything
  2192.  
  2193.     class  = ((struct IntuiMessage *) msg)->Class;
  2194.     code   = ((struct IntuiMessage *) msg)->Code;
  2195.     qual   = ((struct IntuiMessage *) msg)->Qualifier;
  2196.     mousex = ((struct IntuiMessage *) msg)->MouseX;
  2197.     mousey = ((struct IntuiMessage *) msg)->MouseY;
  2198.  
  2199.     switch(class)
  2200.     {
  2201.     case IDCMP_RAWKEY:
  2202.         switch(code)
  2203.         {
  2204.         case SCAN_HELP:
  2205.             helpabout();
  2206.         break;
  2207.         case SCAN_ESCAPE:
  2208.             cleanexit(EXIT_SUCCESS);
  2209.         break;
  2210.         case SCAN_GRAVE:
  2211.             if (qual & IEQUALIFIER_CONTROL)
  2212.             {   decrypt();
  2213.             }
  2214.         break;
  2215.         default:
  2216.         break;
  2217.         }
  2218.     break;
  2219.     case IDCMP_INTUITICKS:
  2220.     {   newover = FUNCTIONS;
  2221.         for (i = 0; i < FUNCTIONS; i++)
  2222.         {   if
  2223.             (   mousex >= gadgets[GID_0_BU1 + i]->LeftEdge
  2224.              && mousex <= gadgets[GID_0_BU1 + i]->LeftEdge + gadgets[GID_0_BU1 + i]->Width  - 1
  2225.              && mousey >= gadgets[GID_0_BU1 + i]->TopEdge
  2226.              && mousey <= gadgets[GID_0_BU1 + i]->TopEdge  + gadgets[GID_0_BU1 + i]->Height - 1
  2227.             )
  2228.             {   newover = i;
  2229.                 break;
  2230.         }   }
  2231.         if (newover != over)
  2232.         {   over = newover;
  2233.             SetGadgetAttrs
  2234.             (   gadgets[GID_0_ST1], MainWindowPtr, NULL,
  2235.                 STRINGA_TextVal, FunctionDesc[over],
  2236.                 TAG_DONE
  2237.             );
  2238.     }   }
  2239.     break;
  2240.     default:
  2241.     break;
  2242.     }
  2243.  
  2244.     return(1);
  2245. }
  2246.  
  2247. /* This function converts register-parameter Hook calling convention into
  2248. standard C conventions. It requires a C compiler that supports
  2249. registerized parameters, such as SAS/C 5.x or greater. */
  2250.  
  2251. AGLOBAL ULONG ASM hookEntry(REG(a0) struct Hook *h, REG(a2) VOID *o, REG(a1) VOID *msg)
  2252. {   // This is the stub function that converts the register-parameters
  2253.     // to stack parameters.
  2254.  
  2255.     return ((*(ULONG (*)(struct Hook *, VOID *, VOID *))(*h->h_SubEntry))(h, o, msg));
  2256. }
  2257.  
  2258. AGLOBAL void InitHook(struct Hook* hook, ULONG (*func)(), void* data)
  2259. {   // Make sure a pointer was passed
  2260.  
  2261.     if (hook)
  2262.     {   // Fill in the Hook fields
  2263.         hook->h_Entry    = (ULONG (*)()) hookEntry;
  2264.         hook->h_SubEntry = func;
  2265.         hook->h_Data     = data;
  2266.     } else
  2267.     {   Printf("Report+: Can't initialize hook (NULL pointer)!");
  2268.         cleanexit(EXIT_FAILURE);
  2269. }   }
  2270.  
  2271. AGLOBAL void clearlist(struct List* ListPtr)
  2272. {   if (ListPtr->lh_Head->ln_Succ) // if list is non-empty
  2273.     {   FreeNameNodes(ListPtr);
  2274.     }
  2275.     NewList(ListPtr); // prepare for reuse
  2276. }
  2277.  
  2278. // Function to free an Exec List of ReAction ListBrowser nodes.
  2279. AGLOBAL void clearreactionlist(struct List* ListPtr)
  2280. {   /* Requirements: listbrowser class must be already open, and list
  2281.     must be detached from gadget*/
  2282.  
  2283.     if (ListPtr->lh_Head->ln_Succ) // if list is non-empty
  2284.     {   FreeListBrowserList(ListPtr);
  2285.     }
  2286.     NewList(ListPtr); // prepare for reuse
  2287. }
  2288.  
  2289. AGLOBAL void openwindow(void)
  2290. {   // Opens a ReAction window.
  2291.  
  2292.     if (!(MainWindowPtr = (struct Window *) DoMethod(WinObject[shared.function], WM_OPEN, NULL)))
  2293.     {   rq("Can't open ReAction window!");        
  2294.     }
  2295.  
  2296.     // Obtain the window wait signal mask.
  2297.     GetAttr(WINDOW_SigMask, WinObject[shared.function], &signal);
  2298.  
  2299.     OffMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_NEW,    NOSUB));
  2300.     OffMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_OPEN,   NOSUB));
  2301.     OffMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVE,   NOSUB));
  2302.     OffMenu(MainWindowPtr, FULLMENUNUM(MN_PROJECT, IN_SAVEAS, NOSUB));
  2303. }
  2304.  
  2305. AGLOBAL ABOOL ra_checkbreak(void)
  2306. {   ULONG result;
  2307.     UWORD code;
  2308.  
  2309.     while ((result = DoMethod(WinObject[shared.function], WM_HANDLEINPUT, &code)) != WMHI_LASTMSG)
  2310.     {   switch (result & WMHI_CLASSMASK)
  2311.         {
  2312.         case IDCMP_RAWKEY:
  2313.             if (code == SCAN_ESCAPE)
  2314.                 return(1);
  2315.         break;
  2316.         case WMHI_CLOSEWINDOW:
  2317.              return(2);
  2318.         break;
  2319.         case WMHI_GADGETUP:
  2320.              if (shared.function == 8)
  2321.              {   if ((result & (WMHI_GADGETMASK)) == GID_8_BU5) // these parentheses are needed!
  2322.                  {   return(1);
  2323.              }   }
  2324.              else
  2325.              {   // assert(shared.function == 10);
  2326.                  if ((result & (WMHI_GADGETMASK)) == GID_10_BU3) // these parentheses are needed!
  2327.                  {   return(1);
  2328.              }   }
  2329.         break;
  2330.         default:
  2331.         break;
  2332.     }   }
  2333.     return(0);
  2334. }
  2335.  
  2336. AGLOBAL void sender(void)
  2337. {   struct Hook SenderHookStruct;
  2338.     STRPTR      stringptr;
  2339.  
  2340.     if (readin("S:Report.sender"))
  2341.     {   /* # Refer: <last>,<first> (<company> ,phone <phone>)<LF>
  2342.            # Path: <email><LF>
  2343.            # ReferID: <developer><LF> */
  2344.  
  2345.         offset = 0;
  2346.         parse("# Refer: ");
  2347.         parse(",");
  2348.         strcpy(report.lastname,  string);
  2349.         parse(" (");
  2350.         strcpy(report.firstname, string);
  2351.         parse(" ,phone ");
  2352.         strcpy(report.company,   string);
  2353.         parse(")\n# Path: ");
  2354.         strcpy(report.phone,     string);
  2355.         parse("\n# ReferID: ");
  2356.         strcpy(report.email,     string);
  2357.         parse("\n");
  2358.         strcpy(report.developer, string);
  2359.     }
  2360.  
  2361.     InitHook(&SenderHookStruct, SenderHookFunc, NULL);
  2362.  
  2363.     /* Create the window object. */
  2364.     lockscreen();
  2365.  
  2366. if (!(WinObject[shared.function] =
  2367. NewObject
  2368. (
  2369.     WINDOW_GetClass(),                    NULL,
  2370.     WA_PubScreen,                         ScreenPtr,
  2371.     WA_ScreenTitle,                       "Report+",
  2372.     WA_Title,                             "Report+: Sender Details",
  2373.     WA_Activate,                          TRUE,
  2374.     WA_DepthGadget,                       TRUE,
  2375.     WA_DragBar,                           TRUE,
  2376.     WA_CloseGadget,                       TRUE,
  2377.     WA_SizeGadget,                        TRUE,
  2378.     WA_IDCMP,                             IDCMP_RAWKEY,
  2379.     WINDOW_IDCMPHook,                     &SenderHookStruct,
  2380.     WINDOW_IDCMPHookBits,                 IDCMP_RAWKEY,
  2381.     WINDOW_MenuStrip,                     MenuPtr,
  2382.     WINDOW_Position,                      WPOS_CENTERSCREEN,
  2383.     WINDOW_ParentGroup,                   sender_gadgets[GID_S_LY1] =
  2384.     NewObject
  2385.     (   LAYOUT_GetClass(),                NULL,
  2386.         LAYOUT_Orientation,               LAYOUT_ORIENT_HORIZ,
  2387.         LAYOUT_SpaceOuter,                TRUE,
  2388.         LAYOUT_DeferLayout,               TRUE,
  2389.         LAYOUT_AddChild,                  NewObject(LAYOUT_GetClass(), NULL,
  2390.             LAYOUT_Orientation,           LAYOUT_ORIENT_VERT,
  2391.             LAYOUT_VertAlignment,         LALIGN_CENTER,
  2392.             LAYOUT_BevelStyle,            BVS_NONE,
  2393.             LAYOUT_AddChild,              NewObject
  2394.             (   LAYOUT_GetClass(),        NULL,
  2395.                 LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  2396.                 LAYOUT_HorizAlignment,    LALIGN_RIGHT,
  2397.                 LAYOUT_BevelStyle,        BVS_NONE,
  2398.                 LAYOUT_AddImage,          NewObject
  2399.                 (   LABEL_GetClass(),     NULL,
  2400.                     // label
  2401.                     LABEL_Text,           "_First name:",
  2402.                     LABEL_Justification,  LJ_RIGHT,
  2403.                     TAG_END
  2404.                 ),
  2405.                 TAG_END
  2406.             ),
  2407.             CHILD_WeightedHeight,         0,
  2408.             LAYOUT_AddChild,              NewObject(LAYOUT_GetClass(), NULL,
  2409.                 // layout
  2410.                 LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  2411.                 LAYOUT_HorizAlignment,    LALIGN_RIGHT,
  2412.                 LAYOUT_BevelStyle,        BVS_NONE,
  2413.                 LAYOUT_AddImage,          NewObject
  2414.                 (   LABEL_GetClass(),     NULL,
  2415.                     // label
  2416.                     LABEL_Text,           "_Last name:",
  2417.                     LABEL_Justification,  LJ_RIGHT,
  2418.                     TAG_END
  2419.                 ),
  2420.             TAG_END),
  2421.             CHILD_WeightedHeight,         0,
  2422.             LAYOUT_AddChild,
  2423.             NewObject
  2424.             (   LAYOUT_GetClass(),        NULL,
  2425.                 LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  2426.                 LAYOUT_HorizAlignment,    LALIGN_RIGHT,
  2427.                 LAYOUT_BevelStyle,        BVS_NONE,
  2428.                 LAYOUT_AddImage,          NewObject
  2429.                 (   LABEL_GetClass(),     NULL,
  2430.                     // label
  2431.                     LABEL_Text,           "_Company:",
  2432.                     LABEL_Justification,  LJ_RIGHT,
  2433.                     TAG_END
  2434.                 ),
  2435.                 TAG_END
  2436.             ),
  2437.             CHILD_WeightedHeight,         0,
  2438.             LAYOUT_AddChild,              NewObject(LAYOUT_GetClass(), NULL,
  2439.                 // layout
  2440.                 LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  2441.                 LAYOUT_HorizAlignment,    LALIGN_RIGHT,
  2442.                 LAYOUT_BevelStyle,        BVS_NONE,
  2443.                 LAYOUT_AddImage,          NewObject
  2444.                 (   LABEL_GetClass(),     NULL,
  2445.                     // label
  2446.                     LABEL_Text,           "_Phone number:",
  2447.                     LABEL_Justification,  LJ_RIGHT,
  2448.                     TAG_END
  2449.                 ),
  2450.                 TAG_END
  2451.             ),
  2452.             CHILD_WeightedHeight,         0,
  2453.             LAYOUT_AddChild,
  2454.             NewObject
  2455.             (   LAYOUT_GetClass(),        NULL,
  2456.                 LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  2457.                 LAYOUT_HorizAlignment,    LALIGN_RIGHT,
  2458.                 LAYOUT_BevelStyle,        BVS_NONE,
  2459.                 LAYOUT_AddImage,          NewObject
  2460.                 (   LABEL_GetClass(),     NULL,
  2461.                     // label
  2462.                     LABEL_Text,           "_Developer number:",
  2463.                     LABEL_Justification,  LJ_RIGHT,
  2464.                     TAG_END
  2465.                 ),
  2466.                 TAG_END
  2467.             ),
  2468.             CHILD_WeightedHeight,         0,
  2469.             LAYOUT_AddChild,
  2470.             NewObject
  2471.             (   LAYOUT_GetClass(),        NULL,
  2472.                 LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  2473.                 LAYOUT_HorizAlignment,    LALIGN_RIGHT,
  2474.                 LAYOUT_BevelStyle,        BVS_NONE,
  2475.                 LAYOUT_AddImage,          NewObject
  2476.                 (   LABEL_GetClass(),     NULL,
  2477.                     // label
  2478.                     LABEL_Text,           "_Email:",
  2479.                     LABEL_Justification,  LJ_RIGHT,
  2480.                 TAG_END),
  2481.             TAG_END),
  2482.             CHILD_WeightedHeight,         0,
  2483.         TAG_END),
  2484.         CHILD_WeightedWidth,              0,
  2485.         LAYOUT_AddChild,
  2486.         NewObject
  2487.         (   LAYOUT_GetClass(),        NULL,
  2488.             LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  2489.             LAYOUT_VertAlignment,     LALIGN_CENTER,
  2490.             LAYOUT_HorizAlignment,    LALIGN_CENTER,
  2491.             LAYOUT_BevelStyle,        BVS_NONE,
  2492.             LAYOUT_AddChild,          sender_gadgets[GID_S_ST1] =
  2493.             NewObject
  2494.             (   STRING_GetClass(),    NULL,
  2495.                 GA_ID,                GID_S_ST1,
  2496.                 STRINGA_TextVal,      report.firstname,
  2497.                 STRINGA_MinVisible,   20,
  2498.                 STRINGA_MaxChars,     MEDFIELD,
  2499.                 GA_TabCycle,          TRUE,
  2500.             TAG_END),
  2501.             LAYOUT_AddChild,          sender_gadgets[GID_S_ST2] =
  2502.             NewObject
  2503.             (   STRING_GetClass(),    NULL,
  2504.                 GA_ID,                GID_S_ST2,
  2505.                 STRINGA_TextVal,      report.lastname,
  2506.                 STRINGA_MinVisible,   20,
  2507.                 STRINGA_MaxChars,     MEDFIELD,
  2508.                 GA_TabCycle,          TRUE,
  2509.             TAG_END),
  2510.             LAYOUT_AddChild,          sender_gadgets[GID_S_ST3] =
  2511.             NewObject
  2512.             (   STRING_GetClass(),    NULL,
  2513.                 GA_ID,                GID_S_ST3,
  2514.                 STRINGA_TextVal,      report.company,
  2515.                 STRINGA_MinVisible,   20,
  2516.                 STRINGA_MaxChars,     MEDFIELD,
  2517.                 GA_TabCycle,          TRUE,
  2518.             TAG_END),
  2519.             LAYOUT_AddChild,          sender_gadgets[GID_S_ST4] =
  2520.             NewObject
  2521.             (   STRING_GetClass(),    NULL,
  2522.                 GA_ID,                GID_S_ST4,
  2523.                 STRINGA_TextVal,      report.phone,
  2524.                 STRINGA_MinVisible,   20,
  2525.                 STRINGA_MaxChars,     MEDFIELD,
  2526.                 GA_TabCycle,          TRUE,
  2527.             TAG_END),
  2528.             LAYOUT_AddChild,          sender_gadgets[GID_S_ST5] =
  2529.             NewObject
  2530.             (   STRING_GetClass(),    NULL,
  2531.                 GA_ID,                GID_S_ST5,
  2532.                 STRINGA_TextVal,      report.developer,
  2533.                 STRINGA_MinVisible,   20,
  2534.                 STRINGA_MaxChars,     MEDFIELD,
  2535.                 GA_TabCycle,          TRUE,
  2536.             TAG_END),
  2537.             LAYOUT_AddChild,          sender_gadgets[GID_S_ST6] =
  2538.             NewObject
  2539.             (   STRING_GetClass(),    NULL,
  2540.                 GA_ID,                GID_S_ST6,
  2541.                 STRINGA_TextVal,      report.email,
  2542.                 STRINGA_MinVisible,   20,
  2543.                 STRINGA_MaxChars,     MEDFIELD,
  2544.                 GA_TabCycle,          TRUE,
  2545.             TAG_END),
  2546.         TAG_END),
  2547.         CHILD_WeightedHeight,     0,
  2548.     TAG_END)
  2549. )))
  2550. {   rq("Can't create ReAction gadgets!");
  2551. }
  2552. unlockscreen();
  2553. openwindow();
  2554.  
  2555.     ActivateLayoutGadget(sender_gadgets[GID_S_LY1], MainWindowPtr, NULL, (Object) sender_gadgets[GID_S_ST1]);
  2556.     loop();
  2557.  
  2558.     /* write out S:Report.sender
  2559.     # Refer: <last>,<first> (<company> ,phone <phone>)<LF>
  2560.     # Path: <email><LF>
  2561.     # ReferID: <developer><LF> */
  2562.  
  2563.     strcpy(report.refer, "# Refer: ");
  2564.     if (!(GetAttr
  2565.     (   STRINGA_TextVal, sender_gadgets[GID_S_ST2], (ULONG *) &stringptr
  2566.     )))
  2567.     {   rq("Unsupported inquiry!"); // should never happen
  2568.     }
  2569.     strcat(report.refer, stringptr);
  2570.     strcat(report.refer, ",");
  2571.     if (!(GetAttr
  2572.     (   STRINGA_TextVal, sender_gadgets[GID_S_ST1], (ULONG *) &stringptr
  2573.     )))
  2574.     {   rq("Unsupported inquiry!"); // should never happen
  2575.     }
  2576.     strcat(report.refer, stringptr);
  2577.     strcat(report.refer, " (");
  2578.     if (!(GetAttr
  2579.     (   STRINGA_TextVal, sender_gadgets[GID_S_ST3], (ULONG *) &stringptr
  2580.     )))
  2581.     {   rq("Unsupported inquiry!"); // should never happen
  2582.     }
  2583.     strcat(report.refer, stringptr);
  2584.     strcat(report.refer, " ,phone ");
  2585.     if (!(GetAttr
  2586.     (   STRINGA_TextVal, sender_gadgets[GID_S_ST4], (ULONG *) &stringptr
  2587.     )))
  2588.     {   rq("Unsupported inquiry!"); // should never happen
  2589.     }
  2590.     strcat(report.refer, stringptr);
  2591.     strcat(report.refer, ")\n");
  2592.  
  2593.     if (!(GetAttr
  2594.     (   STRINGA_TextVal, sender_gadgets[GID_S_ST6], (ULONG *) &stringptr
  2595.     )))
  2596.     {   rq("Unsupported inquiry!"); // should never happen
  2597.     }
  2598.     strcpy(report.path, "# Path: ");
  2599.     strcat(report.path, stringptr);
  2600.     strcat(report.path, "\n");
  2601.  
  2602.     if (!(GetAttr
  2603.     (   STRINGA_TextVal, sender_gadgets[GID_S_ST5], (ULONG *) &stringptr
  2604.     )))
  2605.     {   rq("Unsupported inquiry!"); // should never happen
  2606.     }
  2607.     strcpy(report.referid, "# ReferID: ");
  2608.     strcat(report.referid, stringptr);
  2609.     strcat(report.referid, "\n");
  2610.  
  2611.     strcpy(IOBuffer, report.refer);
  2612.     strcat(IOBuffer, report.path);
  2613.     strcat(IOBuffer, report.referid);
  2614.     
  2615.     writeout("S:Report.sender");
  2616.  
  2617.     closewindow();
  2618. }
  2619.  
  2620. MODULE void sender_loop(ULONG gid)
  2621. {   ;
  2622. }
  2623.  
  2624. AGLOBAL void getversion(STRPTR filename, STRPTR output)
  2625. {   ULONG i;
  2626.     TEXT  commandstring[PATHNAMEFIELD + 1];
  2627.  
  2628.     /* If you have any lock on the file or its directory, this function
  2629.     will fail (returning "?"). */
  2630.  
  2631.     if (ram)
  2632.     {   strcpy(commandstring, "RAM:Version ");
  2633.     } else
  2634.     {   strcpy(commandstring, "Version ");
  2635.     }
  2636.     strcat(commandstring, filename);
  2637.     strcat(commandstring, " >T:ReportPlus.temp");
  2638.     if (!SystemTags(commandstring, SYS_Output, Open("NIL:", MODE_NEWFILE), TAG_DONE))
  2639.     {   readordie("T:ReportPlus.temp");
  2640.         for (i = 0; i <= VLONGFIELD; i++)
  2641.         {   if (IOBuffer[i] == LF)
  2642.             {   IOBuffer[i] = 0;
  2643.                 break;
  2644.         }   }
  2645.         strcpy(output, IOBuffer);
  2646.     } else
  2647.     {   strcpy(output, "?");
  2648. }   }
  2649.  
  2650. AGLOBAL void setbar(ULONG max)
  2651. {   // Ensure we do no more than BARUPDATES updates of the progress bar.
  2652.  
  2653.     increment = max / BARUPDATES;
  2654.     if (increment == 0)
  2655.     {   increment = 1;
  2656. }   }
  2657.  
  2658. AGLOBAL ABOOL dirasl(void)
  2659. {   struct FileRequester* ASLRqPtr;
  2660.     ABOOL                 success;
  2661.  
  2662.     if (!(ASLRqPtr = AllocAslRequestTags(ASL_FileRequest, ASL_Pattern, "#?", ASL_Window, MainWindowPtr, ASL_ExtFlags1, FIL1F_NOFILES, TAG_DONE)))
  2663.     {   rq("Can't create ASL request!");
  2664.     }
  2665.     if (AslRequestTags(ASLRqPtr, ASL_Dir, asldir, ASL_Hail, "Report+ path selector", ASL_FuncFlags, FILF_PATGAD, TAG_DONE))
  2666.     {   strcpy(aslresult, ASLRqPtr->rf_Dir);
  2667.         success = TRUE;
  2668.     } else success = FALSE;
  2669.     FreeAslRequest(ASLRqPtr);
  2670.     return(success);
  2671. }
  2672.  
  2673. AGLOBAL void comma(ULONG value, STRPTR commastring)
  2674. {   ABOOL yes = FALSE;
  2675.     TEXT  valuestring[11];
  2676.  
  2677.     strcpy(commastring, " ,   ,   ,   ");
  2678.     //                    1   5   9
  2679.  
  2680.     valuestring[ 0] = '0' + (value / 1000000000);
  2681.     value %= 1000000000;
  2682.     if (valuestring[ 0] != '0')
  2683.     {   commastring[0] = valuestring[0];
  2684.         yes = TRUE;
  2685.     } else
  2686.     {   commastring[ 0] = ' ';
  2687.         commastring[ 1] = ' ';
  2688.     }
  2689.  
  2690.     valuestring[ 1] = '0' + (value /  100000000);
  2691.     value %=  100000000;
  2692.     if (yes || valuestring[1] != '0')
  2693.     {   commastring[2] = valuestring[1];
  2694.         yes = TRUE;
  2695.     } else commastring[2] = ' ';
  2696.  
  2697.     valuestring[ 2] = '0' + (value /   10000000);
  2698.     value %=   10000000;
  2699.     if (yes || valuestring[2] != '0')
  2700.     {   commastring[3] = valuestring[2];
  2701.         yes = TRUE;
  2702.     } else commastring[3] = ' ';
  2703.  
  2704.     valuestring[ 3] = '0' + (value /    1000000);
  2705.     value %=    1000000;
  2706.     if (yes || valuestring[3] != '0')
  2707.     {   commastring[4] = valuestring[3];
  2708.         yes = TRUE;
  2709.     } else
  2710.     {   commastring[4] = ' ';
  2711.         commastring[5] = ' ';
  2712.     }
  2713.  
  2714.     valuestring[ 4] = '0' + (value /     100000);
  2715.     value %=     100000;
  2716.     if (yes || valuestring[4] != '0')
  2717.     {   commastring[6] = valuestring[4];
  2718.         yes = TRUE;
  2719.     } else commastring[6] = ' ';
  2720.  
  2721.     valuestring[ 5] = '0' + (value /      10000);
  2722.     value %=      10000;
  2723.     if (yes || valuestring[5] != '0')
  2724.     {   commastring[7] = valuestring[5];
  2725.         yes = TRUE;
  2726.     } else commastring[7] = ' ';
  2727.  
  2728.     valuestring[ 6] = '0' + (value /       1000);
  2729.     value %=       1000;
  2730.     if (yes || valuestring[6] != '0')
  2731.     {   commastring[8] = valuestring[6];
  2732.         yes = TRUE;
  2733.     } else
  2734.     {   commastring[8] = ' ';
  2735.         commastring[9] = ' ';
  2736.     }
  2737.  
  2738.     valuestring[ 7] = '0' + (value /        100);
  2739.     value %=        100;
  2740.     if (yes || valuestring[7] != '0')
  2741.     {   commastring[10] = valuestring[7];
  2742.         yes = TRUE;
  2743.     } else commastring[10] = ' ';
  2744.  
  2745.     valuestring[ 8] = '0' + (value /         10);
  2746.     value %=         10;
  2747.     if (yes || valuestring[8] != '0')
  2748.     {   commastring[11] = valuestring[8];
  2749.         // yes = TRUE;
  2750.     } else commastring[11] = ' ';
  2751.  
  2752.     valuestring[ 9] = '0' +  value              ;
  2753.     commastring[12] = valuestring[9];
  2754. }
  2755.  
  2756. AGLOBAL ULONG SenderHookFunc(struct Hook *h, VOID *o, VOID *msg)
  2757. {   /* "When the hook is called, the data argument points to the 
  2758.     window object and message argument to the IntuiMessage." */
  2759.  
  2760.     UWORD code, qual;
  2761.  
  2762.     geta4(); // wait till here before doing anything
  2763.  
  2764.     code = ((struct IntuiMessage *) msg)->Code;
  2765.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  2766.  
  2767.     switch(code)
  2768.     {
  2769.     case SCAN_HELP:
  2770.         helpabout();
  2771.     break;
  2772.     case SCAN_ESCAPE:
  2773.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  2774.         {   cleanexit(EXIT_SUCCESS);
  2775.         } else
  2776.         {   if (shared.function == 1)
  2777.             {   page = 11;
  2778.             } else
  2779.             {   assert(shared.function == 3);
  2780.                 page = 32;
  2781.         }   }
  2782.     break;
  2783.     case SCAN_F:
  2784.         ActivateLayoutGadget(sender_gadgets[GID_S_LY1], MainWindowPtr, NULL, (Object) sender_gadgets[GID_S_ST1]);
  2785.     break;
  2786.     case SCAN_L:
  2787.         ActivateLayoutGadget(sender_gadgets[GID_S_LY1], MainWindowPtr, NULL, (Object) sender_gadgets[GID_S_ST2]);
  2788.     break;
  2789.     case SCAN_C:
  2790.         ActivateLayoutGadget(sender_gadgets[GID_S_LY1], MainWindowPtr, NULL, (Object) sender_gadgets[GID_S_ST3]);
  2791.     break;
  2792.     case SCAN_P:
  2793.         ActivateLayoutGadget(sender_gadgets[GID_S_LY1], MainWindowPtr, NULL, (Object) sender_gadgets[GID_S_ST4]);
  2794.     break;
  2795.     case SCAN_D:
  2796.         ActivateLayoutGadget(sender_gadgets[GID_S_LY1], MainWindowPtr, NULL, (Object) sender_gadgets[GID_S_ST5]);
  2797.     break;
  2798.     case SCAN_E:
  2799.         ActivateLayoutGadget(sender_gadgets[GID_S_LY1], MainWindowPtr, NULL, (Object) sender_gadgets[GID_S_ST6]);
  2800.     break;
  2801.     default:
  2802.     break;
  2803.     }
  2804.  
  2805.     return(1);
  2806. }
  2807.  
  2808. AGLOBAL void addreactionnode(struct List* ListPtr, STRPTR text)
  2809. {   // This is only for single-column lists.
  2810.  
  2811.     struct ListBrowserNode* ListBrowserNodePtr;
  2812.  
  2813.     if (!(ListBrowserNodePtr = AllocListBrowserNode
  2814.     (   1,                   // columns,
  2815.         LBNCA_CopyText,      TRUE,
  2816.         LBNCA_Text,          text,
  2817.         TAG_END
  2818.     )))
  2819.     {   rq("Can't create ReAction listbrowser.gadget node(s)!");
  2820.     }
  2821.     AddTail(ListPtr, (struct Node *) ListBrowserNodePtr); // AddTail() has no return code
  2822. }
  2823.